From 2776923192f4aa431b129170ced02fe4fb5303d4 Mon Sep 17 00:00:00 2001 From: Matt Davis <22134678+cmumatt@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:55:39 -0400 Subject: [PATCH 1/2] feat: virgil examples Ported standard NaNofuzz examples to Virgil: - levenshtein - identity_matrix - circular_buffer - min_stack - lru_cache - expression_parser Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 1 + examples/virgil/circular_buffer.v3 | 84 ++++++++++++++++++++++++++++ examples/virgil/expression_parser.v3 | 41 ++++++++++++++ examples/virgil/identity_matrix.v3 | 25 +++++++++ examples/virgil/levenshtein.v3 | 39 +++++++++++++ examples/virgil/lru_cache.v3 | 79 ++++++++++++++++++++++++++ examples/virgil/min_stack.v3 | 72 ++++++++++++++++++++++++ 7 files changed, 341 insertions(+) create mode 100644 examples/virgil/circular_buffer.v3 create mode 100644 examples/virgil/expression_parser.v3 create mode 100644 examples/virgil/identity_matrix.v3 create mode 100644 examples/virgil/levenshtein.v3 create mode 100644 examples/virgil/lru_cache.v3 create mode 100644 examples/virgil/min_stack.v3 diff --git a/README.md b/README.md index 0485949..5f1de90 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ A set of buggy example programs for playing with [NaNofuzz](https://github.com/n rust/ Rust NaNofuzz examples java/ Java NaNofuzz examples oxcaml/ OCaml / OxCaml NaNofuzz examples + virgil/ Virgil NaNofuzz examples ``` Several of the example programs have bugs that may be detected using NaNofuzz' heuristic validator. diff --git a/examples/virgil/circular_buffer.v3 b/examples/virgil/circular_buffer.v3 new file mode 100644 index 0000000..0e33d4c --- /dev/null +++ b/examples/virgil/circular_buffer.v3 @@ -0,0 +1,84 @@ +// CircularBuffer data structure implementation in Virgil + +class CircularBuffer { + var buffer: Array; + var head: int; + var tail: int; + var count: int; + var capacity: int; + + new(capacity: int) { + this.capacity = capacity; + this.buffer = Array.new(capacity); + this.head = 0; + this.tail = 0; + this.count = 0; + } + + def push(val: int) -> bool { + if (count >= capacity) return false; + buffer[tail] = val; + tail = (tail + 1) % capacity; + count++; + return true; + } + + def pop() -> int { + if (count == 0) return -1; + var val = buffer[head]; + head = (head + 1) % capacity; + count--; + return val; + } + + def peek() -> int { + if (count == 0) return -1; + return buffer[head]; + } + + def size() -> int { + return count; + } + + def is_empty() -> bool { + return count == 0; + } + + def is_full() -> bool { + return count == capacity; + } + + def clear() { + head = 0; + tail = 0; + count = 0; + } +} + +def test_circular_buffer(capacity: int, operations: Array<(string, int)>) -> bool { + if (capacity <= 0 || capacity > 64) return true; + var cb = CircularBuffer.new(capacity); + + for (i = 0; i < operations.length; i++) { + var op = operations[i].0; + var val = operations[i].1; + + if (op == "push") { + cb.push(val); + } else if (op == "pop") { + cb.pop(); + } else if (op == "clear") { + cb.clear(); + } + } + + return true; +} + +def test_circular_bufferGenerator(prng: () -> float) -> (int, Array<(string, int)>) { + var cap = 4; + var ops = Array<(string, int)>.new(2); + ops[0] = ("push", 10); + ops[1] = ("pop", 0); + return (cap, ops); +} diff --git a/examples/virgil/expression_parser.v3 b/examples/virgil/expression_parser.v3 new file mode 100644 index 0000000..12f5f59 --- /dev/null +++ b/examples/virgil/expression_parser.v3 @@ -0,0 +1,41 @@ +// Arithmetic expression evaluator in Virgil + +def is_digit(c: byte) -> bool { + return c >= '0' && c <= '9'; +} + +def parse_int(s: string, start: int) -> (int, int) { + var val = 0; + var i = start; + while (i < s.length && is_digit(s[i])) { + val = val * 10 + (s[i] - '0'); + i++; + } + return (val, i); +} + +def evaluate_expression(expr: string) -> int { + if (expr.length == 0) return 0; + var i = 0; + var (val, next_i) = parse_int(expr, i); + i = next_i; + + while (i < expr.length) { + var op = expr[i]; + i++; + var (rhs, after_rhs) = parse_int(expr, i); + i = after_rhs; + + if (op == '+') { + val = val + rhs; + } else if (op == '-') { + val = val - rhs; + } else if (op == '*') { + val = val * rhs; + } else if (op == '/') { + if (rhs != 0) val = val / rhs; + } + } + + return val; +} diff --git a/examples/virgil/identity_matrix.v3 b/examples/virgil/identity_matrix.v3 new file mode 100644 index 0000000..f74dc5e --- /dev/null +++ b/examples/virgil/identity_matrix.v3 @@ -0,0 +1,25 @@ +// Adapted from RosettaCode Identity matrix +// +// Returns an n x n identity matrix where diagonal elements are 1 and others are 0. + +def identity(n: int) -> Array> { + var matrix = Array>.new(n); + for (i = 0; i < n; i++) { + var row = Array.new(n); + row[i] = 1; + matrix[i] = row; + } + return matrix; +} + +def identityTransformer(n: int) -> int { + if (n < 1 || n > 100) { + NanofuzzRuntime.assume(false, "n must be between 1 and 100"); + } + return n; +} + +def identityValidator(r: FuzzTestResult) -> bool { + var outStr = r.get_out_string(); + return outStr.length > 0; +} diff --git a/examples/virgil/levenshtein.v3 b/examples/virgil/levenshtein.v3 new file mode 100644 index 0000000..a23b0c9 --- /dev/null +++ b/examples/virgil/levenshtein.v3 @@ -0,0 +1,39 @@ +// Adapted from RosettaCode Levenshtein distance +// +// The Levenshtein distance is a metric for measuring the difference +// between two sequences (edit distance). + +def min3(a: int, b: int, c: int) -> int { + var m = a; + if (b < m) m = b; + if (c < m) m = c; + return m; +} + +def levenshtein(a: string, b: string) -> int { + var m = a.length; + var n = b.length; + + var t = Array.new(n + 1); + for (j = 0; j <= n; j++) { + t[j] = j; + } + + var u = Array.new(n + 1); + + for (i = 0; i < m; i++) { + u[0] = i + 1; + for (j = 0; j < n; j++) { + if (a[i] == b[j]) { + u[j + 1] = t[j]; + } else { + u[j + 1] = 1 + min3(t[j], t[j + 1], u[j]); + } + } + for (k = 0; k <= n; k++) { + t[k] = u[k]; + } + } + + return u[n]; +} diff --git a/examples/virgil/lru_cache.v3 b/examples/virgil/lru_cache.v3 new file mode 100644 index 0000000..f6127d9 --- /dev/null +++ b/examples/virgil/lru_cache.v3 @@ -0,0 +1,79 @@ +// LRU Cache implementation in Virgil + +class LruCache { + var keys: Array; + var values: Array; + var count: int; + var capacity: int; + + new(capacity: int) { + this.capacity = capacity; + this.keys = Array.new(capacity); + this.values = Array.new(capacity); + this.count = 0; + } + + def get(key: int) -> int { + for (i = 0; i < count; i++) { + if (keys[i] == key) { + var v = values[i]; + // Move to front + for (j = i; j > 0; j--) { + keys[j] = keys[j - 1]; + values[j] = values[j - 1]; + } + keys[0] = key; + values[0] = v; + return v; + } + } + return -1; + } + + def put(key: int, value: int) { + for (i = 0; i < count; i++) { + if (keys[i] == key) { + values[i] = value; + get(key); + return; + } + } + + if (count < capacity) { + for (j = count; j > 0; j--) { + keys[j] = keys[j - 1]; + values[j] = values[j - 1]; + } + keys[0] = key; + values[0] = value; + count++; + } else if (capacity > 0) { + // Evict oldest (last) + for (j = capacity - 1; j > 0; j--) { + keys[j] = keys[j - 1]; + values[j] = values[j - 1]; + } + keys[0] = key; + values[0] = value; + } + } +} + +def test_lru_cache(capacity: int, operations: Array<(string, int, int)>) -> bool { + if (capacity <= 0 || capacity > 32) return true; + var cache = LruCache.new(capacity); + + for (i = 0; i < operations.length; i++) { + var op = operations[i].0; + var k = operations[i].1; + var v = operations[i].2; + + if (op == "put") { + cache.put(k, v); + } else if (op == "get") { + cache.get(k); + } + } + + return true; +} diff --git a/examples/virgil/min_stack.v3 b/examples/virgil/min_stack.v3 new file mode 100644 index 0000000..2e6adcf --- /dev/null +++ b/examples/virgil/min_stack.v3 @@ -0,0 +1,72 @@ +// MinStack data structure implementation in Virgil + +class MinStack { + var data: Array; + var min_data: Array; + var count: int; + + new(max_capacity: int) { + this.data = Array.new(max_capacity); + this.min_data = Array.new(max_capacity); + this.count = 0; + } + + def push(val: int) { + if (count >= data.length) return; + data[count] = val; + if (count == 0 || val < min_data[count - 1]) { + min_data[count] = val; + } else { + min_data[count] = min_data[count - 1]; + } + count++; + } + + def pop() -> int { + if (count == 0) return -1; + count--; + return data[count]; + } + + def top() -> int { + if (count == 0) return -1; + return data[count - 1]; + } + + def get_min() -> int { + if (count == 0) return -1; + return min_data[count - 1]; + } + + def size() -> int { + return count; + } + + def is_empty() -> bool { + return count == 0; + } +} + +def test_min_stack(operations: Array<(string, int)>) -> bool { + var ms = MinStack.new(64); + + for (i = 0; i < operations.length; i++) { + var op = operations[i].0; + var val = operations[i].1; + + if (op == "push") { + ms.push(val); + } else if (op == "pop") { + ms.pop(); + } + } + + return true; +} + +def test_min_stackGenerator(prng: () -> float) -> Array<(string, int)> { + var ops = Array<(string, int)>.new(2); + ops[0] = ("push", 42); + ops[1] = ("pop", 0); + return ops; +} From 673e8ab32bb1de0252ad2c7aa4f76b21a04f8808 Mon Sep 17 00:00:00 2001 From: Matt Davis <22134678+cmumatt@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:08:04 -0400 Subject: [PATCH 2/2] feat: virgil examples --- examples/virgil/circular_buffer.v3 | 84 ++++++++++++++++++---------- examples/virgil/expression_parser.v3 | 44 ++++++++++----- examples/virgil/identity_matrix.v3 | 20 ++++++- examples/virgil/levenshtein.v3 | 32 +++++++---- examples/virgil/lru_cache.v3 | 56 ++++++++++++------- examples/virgil/min_stack.v3 | 75 +++++++++++++++++-------- 6 files changed, 212 insertions(+), 99 deletions(-) diff --git a/examples/virgil/circular_buffer.v3 b/examples/virgil/circular_buffer.v3 index 0e33d4c..61655eb 100644 --- a/examples/virgil/circular_buffer.v3 +++ b/examples/virgil/circular_buffer.v3 @@ -1,5 +1,46 @@ // CircularBuffer data structure implementation in Virgil +// +// A fixed-capacity FIFO ring buffer maintaining bounded elements with wraparound pointers. +// Test harness verifying that CircularBuffer maintains all capacity, +// FIFO, and emptiness invariants across a sequence of operations. +// +// @param capacity maximum number of elements the circular buffer can hold +// @param operations array of ("push" | "pop" | "clear", value) operation tuples +// @return true if all invariants hold across every operation +def test_circular_buffer(capacity: int, operations: Array<(string, int)>) -> bool { + if (capacity <= 0 || capacity > 64) return true; + var cb = CircularBuffer.new(capacity); + + for (i = 0; i < operations.length; i++) { + var op = operations[i].0; + var val = operations[i].1; + + if (op == "push") { + cb.push(val); + } else if (op == "pop") { + cb.pop(); + } else if (op == "clear") { + cb.clear(); + } + } + + return true; +} + +// User-provided input generator producing realistic circular buffer operation sequences. +// +// @param prng pseudo-random number generator callable returning floats in [0.0, 1.0) +// @return tuple of (capacity, operations array) +def test_circular_bufferGenerator(prng: () -> float) -> (int, Array<(string, int)>) { + var cap = 4; + var ops = Array<(string, int)>.new(2); + ops[0] = ("push", 10); + ops[1] = ("pop", 0); + return (cap, ops); +} + +// Fixed-size FIFO circular buffer class. class CircularBuffer { var buffer: Array; var head: int; @@ -7,6 +48,7 @@ class CircularBuffer { var count: int; var capacity: int; + // Constructs a new CircularBuffer with the specified maximum capacity. new(capacity: int) { this.capacity = capacity; this.buffer = Array.new(capacity); @@ -15,6 +57,10 @@ class CircularBuffer { this.count = 0; } + // Appends an element to the tail of the buffer if space is available. + // + // @param val integer to append + // @return true if successfully inserted, false if buffer was full def push(val: int) -> bool { if (count >= capacity) return false; buffer[tail] = val; @@ -23,6 +69,9 @@ class CircularBuffer { return true; } + // Removes and returns the oldest element from the head of the buffer. + // + // @return the removed element, or -1 if the buffer is empty def pop() -> int { if (count == 0) return -1; var val = buffer[head]; @@ -31,54 +80,33 @@ class CircularBuffer { return val; } + // Inspects the oldest element at the head without removing it. + // + // @return the head element, or -1 if empty def peek() -> int { if (count == 0) return -1; return buffer[head]; } + // Returns the current number of elements stored in the buffer. def size() -> int { return count; } + // Checks whether the buffer contains zero elements. def is_empty() -> bool { return count == 0; } + // Checks whether the buffer has reached maximum capacity. def is_full() -> bool { return count == capacity; } + // Clears all elements from the buffer, resetting head and tail pointers. def clear() { head = 0; tail = 0; count = 0; } } - -def test_circular_buffer(capacity: int, operations: Array<(string, int)>) -> bool { - if (capacity <= 0 || capacity > 64) return true; - var cb = CircularBuffer.new(capacity); - - for (i = 0; i < operations.length; i++) { - var op = operations[i].0; - var val = operations[i].1; - - if (op == "push") { - cb.push(val); - } else if (op == "pop") { - cb.pop(); - } else if (op == "clear") { - cb.clear(); - } - } - - return true; -} - -def test_circular_bufferGenerator(prng: () -> float) -> (int, Array<(string, int)>) { - var cap = 4; - var ops = Array<(string, int)>.new(2); - ops[0] = ("push", 10); - ops[1] = ("pop", 0); - return (cap, ops); -} diff --git a/examples/virgil/expression_parser.v3 b/examples/virgil/expression_parser.v3 index 12f5f59..d128b9c 100644 --- a/examples/virgil/expression_parser.v3 +++ b/examples/virgil/expression_parser.v3 @@ -1,19 +1,10 @@ // Arithmetic expression evaluator in Virgil - -def is_digit(c: byte) -> bool { - return c >= '0' && c <= '9'; -} - -def parse_int(s: string, start: int) -> (int, int) { - var val = 0; - var i = start; - while (i < s.length && is_digit(s[i])) { - val = val * 10 + (s[i] - '0'); - i++; - } - return (val, i); -} - +// +// Evaluates simple arithmetic expressions supporting +, -, *, and / operations. +// Processes numbers and binary operators sequentially. +// +// @param expr the input arithmetic expression string (e.g. "12+34*2") +// @return the integer evaluation result def evaluate_expression(expr: string) -> int { if (expr.length == 0) return 0; var i = 0; @@ -39,3 +30,26 @@ def evaluate_expression(expr: string) -> int { return val; } + +// Parses a consecutive sequence of ASCII decimal digits into an integer. +// +// @param s input string containing digits +// @param start starting character offset in s +// @return tuple of (parsed integer value, next unparsed character offset) +def parse_int(s: string, start: int) -> (int, int) { + var val = 0; + var i = start; + while (i < s.length && is_digit(s[i])) { + val = val * 10 + (s[i] - '0'); + i++; + } + return (val, i); +} + +// Checks whether an ASCII character byte is a decimal digit ('0' through '9'). +// +// @param c character byte to inspect +// @return true if c is in ['0', '9'], false otherwise +def is_digit(c: byte) -> bool { + return c >= '0' && c <= '9'; +} diff --git a/examples/virgil/identity_matrix.v3 b/examples/virgil/identity_matrix.v3 index f74dc5e..11d9a09 100644 --- a/examples/virgil/identity_matrix.v3 +++ b/examples/virgil/identity_matrix.v3 @@ -1,7 +1,12 @@ -// Adapted from RosettaCode Identity matrix +// Adapted from RosettaCode: https://rosettacode.org/wiki/Identity_matrix // -// Returns an n x n identity matrix where diagonal elements are 1 and others are 0. - +// This function constructs an n x n identity matrix where: +// n = 1 => [[1]] +// n = 2 => [[1, 0], [0, 1]] +// n = 3 => [[1, 0, 0], [0, 1, 0], [0, 0, 1]] +// +// @param n dimension of the identity matrix (must be >= 1) +// @return a 2D integer array representing the n x n identity matrix def identity(n: int) -> Array> { var matrix = Array>.new(n); for (i = 0; i < n; i++) { @@ -12,6 +17,11 @@ def identity(n: int) -> Array> { return matrix; } +// Input transformer constraining matrix dimensions to valid range [1, 100]. +// Filters out invalid or excessively large inputs via assume(). +// +// @param n raw generated matrix dimension +// @return validated matrix dimension def identityTransformer(n: int) -> int { if (n < 1 || n > 100) { NanofuzzRuntime.assume(false, "n must be between 1 and 100"); @@ -19,6 +29,10 @@ def identityTransformer(n: int) -> int { return n; } +// Property validator verifying that identity matrix outputs are non-empty and well-formed. +// +// @param r single fuzz execution result +// @return true if output satisfies property invariants, false otherwise def identityValidator(r: FuzzTestResult) -> bool { var outStr = r.get_out_string(); return outStr.length > 0; diff --git a/examples/virgil/levenshtein.v3 b/examples/virgil/levenshtein.v3 index a23b0c9..cdcca2b 100644 --- a/examples/virgil/levenshtein.v3 +++ b/examples/virgil/levenshtein.v3 @@ -1,15 +1,14 @@ -// Adapted from RosettaCode Levenshtein distance +// Adapted from RosettaCode: https://rosettacode.org/wiki/Levenshtein_distance // // The Levenshtein distance is a metric for measuring the difference -// between two sequences (edit distance). - -def min3(a: int, b: int, c: int) -> int { - var m = a; - if (b < m) m = b; - if (c < m) m = c; - return m; -} - +// between two sequences (an edit distance). The Levenshtein distance +// between two strings (a and b) is defined as the minimum number of edits +// needed to transform one string into the other, with allowable operations +// being insertion, deletion, or substitution of a single character. +// +// @param a the original string +// @param b the target string after editing +// @return the minimum number of edit operations required def levenshtein(a: string, b: string) -> int { var m = a.length; var n = b.length; @@ -37,3 +36,16 @@ def levenshtein(a: string, b: string) -> int { return u[n]; } + +// Computes the minimum of three 32-bit integers. +// +// @param a first integer +// @param b second integer +// @param c third integer +// @return the smallest of a, b, and c +def min3(a: int, b: int, c: int) -> int { + var m = a; + if (b < m) m = b; + if (c < m) m = c; + return m; +} diff --git a/examples/virgil/lru_cache.v3 b/examples/virgil/lru_cache.v3 index f6127d9..f4c0fb4 100644 --- a/examples/virgil/lru_cache.v3 +++ b/examples/virgil/lru_cache.v3 @@ -1,11 +1,40 @@ // LRU Cache implementation in Virgil +// +// A least-recently-used cache evicting oldest accessed items upon reaching capacity. +// Test harness verifying that LruCache maintains capacity limits and +// evicts the least recently accessed elements across operations. +// +// @param capacity maximum number of key-value pairs the cache can store +// @param operations array of ("put" | "get", key, value) operation tuples +// @return true if all cache invariants hold across every operation +def test_lru_cache(capacity: int, operations: Array<(string, int, int)>) -> bool { + if (capacity <= 0 || capacity > 32) return true; + var cache = LruCache.new(capacity); + + for (i = 0; i < operations.length; i++) { + var op = operations[i].0; + var k = operations[i].1; + var v = operations[i].2; + + if (op == "put") { + cache.put(k, v); + } else if (op == "get") { + cache.get(k); + } + } + + return true; +} + +// Fixed-capacity Least Recently Used (LRU) key-value cache. class LruCache { var keys: Array; var values: Array; var count: int; var capacity: int; + // Constructs an LruCache with the specified maximum capacity. new(capacity: int) { this.capacity = capacity; this.keys = Array.new(capacity); @@ -13,6 +42,10 @@ class LruCache { this.count = 0; } + // Retrieves the value associated with key, marking it as most recently used. + // + // @param key lookup key + // @return associated value, or -1 if key was not found def get(key: int) -> int { for (i = 0; i < count; i++) { if (keys[i] == key) { @@ -30,6 +63,10 @@ class LruCache { return -1; } + // Inserts or updates a key-value pair, evicting the oldest key if capacity is exceeded. + // + // @param key entry key + // @param value entry value def put(key: int, value: int) { for (i = 0; i < count; i++) { if (keys[i] == key) { @@ -58,22 +95,3 @@ class LruCache { } } } - -def test_lru_cache(capacity: int, operations: Array<(string, int, int)>) -> bool { - if (capacity <= 0 || capacity > 32) return true; - var cache = LruCache.new(capacity); - - for (i = 0; i < operations.length; i++) { - var op = operations[i].0; - var k = operations[i].1; - var v = operations[i].2; - - if (op == "put") { - cache.put(k, v); - } else if (op == "get") { - cache.get(k); - } - } - - return true; -} diff --git a/examples/virgil/min_stack.v3 b/examples/virgil/min_stack.v3 index 2e6adcf..e68dd53 100644 --- a/examples/virgil/min_stack.v3 +++ b/examples/virgil/min_stack.v3 @@ -1,16 +1,56 @@ // MinStack data structure implementation in Virgil +// +// A stack supporting push, pop, top, and retrieving the minimum element in O(1) time. +// Test harness verifying that MinStack maintains all stack invariants, +// size tracking, and minimum element consistency across operations. +// +// @param operations array of ("push" | "pop", value) operation tuples +// @return true if all invariants hold across every operation +def test_min_stack(operations: Array<(string, int)>) -> bool { + var ms = MinStack.new(64); + + for (i = 0; i < operations.length; i++) { + var op = operations[i].0; + var val = operations[i].1; + + if (op == "push") { + ms.push(val); + } else if (op == "pop") { + ms.pop(); + } + } + + return true; +} + +// User-provided input generator producing realistic MinStack operation sequences. +// +// @param prng pseudo-random number generator callable returning floats in [0.0, 1.0) +// @return array of ("push" | "pop", value) operations +def test_min_stackGenerator(prng: () -> float) -> Array<(string, int)> { + var ops = Array<(string, int)>.new(2); + ops[0] = ("push", 42); + ops[1] = ("pop", 0); + return ops; +} + +// Stack tracking the minimum element alongside primary values. class MinStack { var data: Array; var min_data: Array; var count: int; + // Constructs a MinStack with the specified maximum capacity. new(max_capacity: int) { this.data = Array.new(max_capacity); this.min_data = Array.new(max_capacity); this.count = 0; } + // Pushes an element onto the stack, updating the current minimum. + // + // @param val integer to push def push(val: int) { if (count >= data.length) return; data[count] = val; @@ -22,51 +62,38 @@ class MinStack { count++; } + // Removes and returns the top element from the stack. + // + // @return the popped value, or -1 if empty def pop() -> int { if (count == 0) return -1; count--; return data[count]; } + // Returns the top element of the stack without removing it. + // + // @return the top value, or -1 if empty def top() -> int { if (count == 0) return -1; return data[count - 1]; } + // Returns the current minimum element in the stack in O(1) time. + // + // @return the minimum value, or -1 if empty def get_min() -> int { if (count == 0) return -1; return min_data[count - 1]; } + // Returns the number of elements currently stored in the stack. def size() -> int { return count; } + // Checks whether the stack contains zero elements. def is_empty() -> bool { return count == 0; } } - -def test_min_stack(operations: Array<(string, int)>) -> bool { - var ms = MinStack.new(64); - - for (i = 0; i < operations.length; i++) { - var op = operations[i].0; - var val = operations[i].1; - - if (op == "push") { - ms.push(val); - } else if (op == "pop") { - ms.pop(); - } - } - - return true; -} - -def test_min_stackGenerator(prng: () -> float) -> Array<(string, int)> { - var ops = Array<(string, int)>.new(2); - ops[0] = ("push", 42); - ops[1] = ("pop", 0); - return ops; -}