diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..27b720e3 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "semi": false, + "trailingComma": "none" +} diff --git a/src/Array.mo b/src/Array.mo index f95191f6..653418ec 100644 --- a/src/Array.mo +++ b/src/Array.mo @@ -61,9 +61,9 @@ module { var i = 0; while (i < size) { array[i] := generator i; - i += 1; + i += 1 }; - array; + array }; /// Transforms a mutable array into an immutable array. @@ -96,15 +96,15 @@ module { public func thaw(array : [A]) : [var A] { let size = array.size(); if (size == 0) { - return [var]; + return [var] }; let newArray = Prim.Array_init(size, array[0]); var i = 0; while (i < size) { newArray[i] := array[i]; - i += 1; + i += 1 }; - newArray; + newArray }; /// Tests if two arrays contain equal values (i.e. they represent the same @@ -128,16 +128,16 @@ module { let size1 = array1.size(); let size2 = array2.size(); if (size1 != size2) { - return false; + return false }; var i = 0; while (i < size1) { if (not equal(array1[i], array2[i])) { - return false; + return false }; - i += 1; + i += 1 }; - return true; + return true }; /// Returns the first value in `array` for which `predicate` returns true. @@ -155,10 +155,10 @@ module { public func find(array : [X], predicate : X -> Bool) : ?X { for (element in array.vals()) { if (predicate element) { - return ?element; - }; + return ?element + } }; - return null; + return null }; /// Create a new array by appending the values of `array1` and `array2`. @@ -180,12 +180,12 @@ module { size1 + size2, func i { if (i < size1) { - array1[i]; + array1[i] } else { - array2[i - size1]; - }; - }, - ); + array2[i - size1] + } + } + ) }; // FIXME this example stack overflows. Should test with new implementation of sortInPlace @@ -205,7 +205,7 @@ module { public func sort(array : [X], compare : (X, X) -> Order.Order) : [X] { let temp : [var X] = thaw(array); sortInPlace(temp, compare); - freeze(temp); + freeze(temp) }; /// Sorts the elements in the array, __in place__, according to `compare`. @@ -227,7 +227,7 @@ module { // Stable merge sort in a bottom-up iterative style. Same algorithm as the sort in Buffer. let size = array.size(); if (size == 0) { - return; + return }; let scratchSpace = Prim.Array_init(size, array[0]); @@ -238,10 +238,10 @@ module { var leftStart = 0; // selects the current left subarray being merged while (leftStart < sizeDec) { let mid : Nat = if (leftStart + currSize - 1 : Nat < sizeDec) { - leftStart + currSize - 1; + leftStart + currSize - 1 } else { sizeDec }; let rightEnd : Nat = if (leftStart + (2 * currSize) - 1 : Nat < sizeDec) { - leftStart + (2 * currSize) - 1; + leftStart + (2 * currSize) - 1 } else { sizeDec }; // Merge subarrays elements[leftStart...mid] and elements[mid+1...rightEnd] @@ -254,37 +254,37 @@ module { switch (compare(leftElement, rightElement)) { case (#less or #equal) { scratchSpace[nextSorted] := leftElement; - left += 1; + left += 1 }; case (#greater) { scratchSpace[nextSorted] := rightElement; - right += 1; - }; + right += 1 + } }; - nextSorted += 1; + nextSorted += 1 }; while (left < mid + 1) { scratchSpace[nextSorted] := array[left]; nextSorted += 1; - left += 1; + left += 1 }; while (right < rightEnd + 1) { scratchSpace[nextSorted] := array[right]; nextSorted += 1; - right += 1; + right += 1 }; // Copy over merged elements var i = leftStart; while (i < rightEnd + 1) { array[i] := scratchSpace[i]; - i += 1; + i += 1 }; - leftStart += 2 * currSize; + leftStart += 2 * currSize }; - currSize *= 2; - }; + currSize *= 2 + } }; /// Creates a new array by reversing the order of elements in `array`. @@ -301,7 +301,7 @@ module { /// Space: O(1) public func reverse(array : [X]) : [X] { let size = array.size(); - Prim.Array_tabulate(size, func i = array[size - i - 1]); + Prim.Array_tabulate(size, func i = array[size - i - 1]) }; /// Creates a new array by applying `f` to each element in `array`. `f` "maps" @@ -339,23 +339,23 @@ module { func i { if (predicate(array[i])) { count += 1; - true; + true } else { - false; - }; - }, + false + } + } ); var nextKeep = 0; Prim.Array_tabulate( count, func _ { while (not keep[nextKeep]) { - nextKeep += 1; + nextKeep += 1 }; nextKeep += 1; - array[nextKeep - 1]; - }, - ); + array[nextKeep - 1] + } + ) }; // FIXME the arguments ordering to the higher order function are flipped @@ -403,13 +403,13 @@ module { switch (result) { case (?element) { count += 1; - result; + result }; case null { - null; - }; - }; - }, + null + } + } + } ); var nextSome = 0; @@ -417,17 +417,17 @@ module { count, func _ { while (Option.isNull(options[nextSome])) { - nextSome += 1; + nextSome += 1 }; nextSome += 1; switch (options[nextSome - 1]) { case (?element) element; case null { - Prim.trap "Malformed array in mapFilter"; - }; - }; - }, - ); + Prim.trap "Malformed array in mapFilter" + } + } + } + ) }; /// Creates a new array by applying `f` to each element in `array`. @@ -462,20 +462,20 @@ module { func i { switch (f(array[i])) { case (#ok element) { - ?element; + ?element }; case (#err e) { switch (error) { case null { // only take the first error - error := ?(#err e); + error := ?(#err e) }; - case _ {}; + case _ {} }; - null; - }; - }; - }, + null + } + } + } ); switch error { @@ -487,20 +487,20 @@ module { func element { switch element { case (?element) { - element; + element }; case null { - Prim.trap "Malformed array in mapResults"; - }; - }; - }, - ), - ); + Prim.trap "Malformed array in mapResults" + } + } + } + ) + ) }; case (?error) { - error; - }; - }; + error + } + } }; /// Creates a new array by applying `k` to each element in `array`, @@ -525,8 +525,8 @@ module { func i { let subArray = k(array[i]); flatSize += subArray.size(); - subArray; - }, + subArray + } ); // could replace with a call to flatten, // but it would require an extra pass (to compute `flatSize`) @@ -540,11 +540,11 @@ module { inner += 1; if (inner == subArray.size()) { inner := 0; - outer += 1; + outer += 1 }; - element; - }, - ); + element + } + ) }; /// Collapses the elements in `array` into a single value by starting with `base` @@ -572,10 +572,10 @@ module { var accumulation = base; for (element in array.vals()) { - accumulation := combine(accumulation, element); + accumulation := combine(accumulation, element) }; - accumulation; + accumulation }; // FIXME the type arguments are reverse order from Buffer @@ -602,10 +602,10 @@ module { var i = size; while (i > 0) { i -= 1; - accumulation := combine(array[i], accumulation); + accumulation := combine(array[i], accumulation) }; - accumulation; + accumulation }; /// Flattens the array of arrays into a single array. Retains the original @@ -623,7 +623,7 @@ module { public func flatten(arrays : [[X]]) : [X] { var flatSize = 0; for (subArray in arrays.vals()) { - flatSize += subArray.size(); + flatSize += subArray.size() }; var outer = 0; @@ -633,13 +633,13 @@ module { func _ { while (inner == arrays[outer].size()) { inner := 0; - outer += 1; + outer += 1 }; let element = arrays[outer][inner]; inner += 1; - element; - }, - ); + element + } + ) }; /// Create an array containing a single value. @@ -697,5 +697,5 @@ module { /// Runtime: O(1) /// /// Space: O(1) - public func keys(array : [X]) : I.Iter = array.keys(); -}; + public func keys(array : [X]) : I.Iter = array.keys() +} diff --git a/src/AssocList.mo b/src/AssocList.mo index a43165c3..af57431d 100644 --- a/src/AssocList.mo +++ b/src/AssocList.mo @@ -14,7 +14,7 @@ module { public func find( al : AssocList, k : K, - k_eq : (K, K) -> Bool, + k_eq : (K, K) -> Bool ) : ?V { func rec(al : AssocList) : ?V { label profile_assocList_find_rec : (?V) switch (al) { @@ -22,17 +22,17 @@ module { case (?((hd_k, hd_v), tl)) { if (k_eq(k, hd_k)) { label profile_assocList_find_end_success : (?V) { - ?hd_v; - }; + ?hd_v + } } else { - rec(tl); - }; - }; - }; + rec(tl) + } + } + } }; label profile_assocList_find_begin : (?V) { - rec(al); - }; + rec(al) + } }; /// replace the value associated with a given key, or add it, if missing. @@ -41,15 +41,15 @@ module { al : AssocList, k : K, k_eq : (K, K) -> Bool, - ov : ?V, + ov : ?V ) : (AssocList, ?V) { func rec(al : AssocList) : (AssocList, ?V) { switch (al) { case (null) { switch ov { case (null) { (null, null) }; - case (?v) { (?((k, v), null), null) }; - }; + case (?v) { (?((k, v), null), null) } + } }; case (?((hd_k, hd_v), tl)) { if (k_eq(k, hd_k)) { @@ -57,16 +57,16 @@ module { // return old value switch ov { case (null) { (tl, ?hd_v) }; - case (?v) { (?((hd_k, v), tl), ?hd_v) }; - }; + case (?v) { (?((hd_k, v), tl), ?hd_v) } + } } else { let (tl2, old_v) = rec(tl); - (?((hd_k, hd_v), tl2), old_v); - }; - }; - }; + (?((hd_k, hd_v), tl2), old_v) + } + } + } }; - rec(al); + rec(al) }; /// The entries of the final list consist of those pairs of @@ -75,7 +75,7 @@ module { public func diff( al1 : AssocList, al2 : AssocList, - keq : (K, K) -> Bool, + keq : (K, K) -> Bool ) : AssocList { func rec(al1 : AssocList) : AssocList { switch al1 { @@ -83,37 +83,37 @@ module { case (?((k, v1), tl)) { switch (find(al2, k, keq)) { case (null) { ?((k, v1), rec(tl)) }; - case (?v2) { rec(tl) }; - }; - }; - }; + case (?v2) { rec(tl) } + } + } + } }; - rec(al1); + rec(al1) }; /// Transform and combine the entries of two association lists. public func mapAppend( al1 : AssocList, al2 : AssocList, - vbin : (?V, ?W) -> X, + vbin : (?V, ?W) -> X ) : AssocList = label profile_assocList_mapAppend : AssocList { func rec(al1 : AssocList, al2 : AssocList) : AssocList = label profile_assocList_mapAppend_rec : AssocList { switch (al1, al2) { case (null, null) { null }; case (?((k, v), al1_), _) { ?((k, vbin(?v, null)), rec(al1_, al2)) }; - case (null, ?((k, v), al2_)) { ?((k, vbin(null, ?v)), rec(null, al2_)) }; - }; + case (null, ?((k, v), al2_)) { ?((k, vbin(null, ?v)), rec(null, al2_)) } + } }; - rec(al1, al2); + rec(al1, al2) }; /// Specialized version of `disj`, optimized for disjoint sub-spaces of keyspace (no matching keys). public func disjDisjoint( al1 : AssocList, al2 : AssocList, - vbin : (?V, ?W) -> X, + vbin : (?V, ?W) -> X ) : AssocList = label profile_assocList_disjDisjoint : AssocList { - mapAppend(al1, al2, vbin); + mapAppend(al1, al2, vbin) }; /// This operation generalizes the notion of "set union" to finite maps. @@ -128,7 +128,7 @@ module { al1 : AssocList, al2 : AssocList, keq : (K, K) -> Bool, - vbin : (?V, ?W) -> X, + vbin : (?V, ?W) -> X ) : AssocList { func rec1(al1Rec : AssocList) : AssocList { switch al1Rec { @@ -139,22 +139,22 @@ module { case (?((k, v2), tl)) { switch (find(al1, k, keq)) { case (null) { ?((k, vbin(null, ?v2)), rec2(tl)) }; - case (?v1) { ?((k, vbin(?v1, ?v2)), rec2(tl)) }; - }; - }; - }; + case (?v1) { ?((k, vbin(?v1, ?v2)), rec2(tl)) } + } + } + } }; - rec2(al2); + rec2(al2) }; case (?((k, v1), tl)) { switch (find(al2, k, keq)) { case (null) { ?((k, vbin(?v1, null)), rec1(tl)) }; - case (?v2) { /* handled above */ rec1(tl) }; - }; - }; - }; + case (?v2) { /* handled above */ rec1(tl) } + } + } + } }; - rec1(al1); + rec1(al1) }; /// This operation generalizes the notion of "set intersection" to @@ -165,7 +165,7 @@ module { al1 : AssocList, al2 : AssocList, keq : (K, K) -> Bool, - vbin : (V, W) -> X, + vbin : (V, W) -> X ) : AssocList { func rec(al1 : AssocList) : AssocList { switch al1 { @@ -173,27 +173,27 @@ module { case (?((k, v1), tl)) { switch (find(al2, k, keq)) { case (null) { rec(tl) }; - case (?v2) { ?((k, vbin(v1, v2)), rec(tl)) }; - }; - }; - }; + case (?v2) { ?((k, vbin(v1, v2)), rec(tl)) } + } + } + } }; - rec(al1); + rec(al1) }; /// Fold the entries based on the recursive list structure. public func fold( al : AssocList, nil : X, - cons : (K, V, X) -> X, + cons : (K, V, X) -> X ) : X { func rec(al : AssocList) : X { switch al { case null { nil }; - case (?((k, v), t)) { cons(k, v, rec(t)) }; - }; + case (?((k, v), t)) { cons(k, v, rec(t)) } + } }; - rec(al); + rec(al) }; -}; +} diff --git a/src/Blob.mo b/src/Blob.mo index 8d7b59a1..7c228d80 100644 --- a/src/Blob.mo +++ b/src/Blob.mo @@ -35,7 +35,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Blob, y : Blob) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Creates a blob from an array of bytes, by copying each element. @@ -50,4 +50,4 @@ module { /// Creates a mutable array of bytes from a blob, by copying each element. public let toArrayMut : Blob -> [var Nat8] = Prim.blobToArrayMut; -}; +} diff --git a/src/Bool.mo b/src/Bool.mo index b70f8bdd..bb74545f 100644 --- a/src/Bool.mo +++ b/src/Bool.mo @@ -13,7 +13,7 @@ module { /// Conversion. public func toText(x : Bool) : Text { - if x { "true" } else { "false" }; + if x { "true" } else { "false" } }; /// Returns `x and y`. @@ -24,7 +24,7 @@ module { /// Returns exclusive or of `x` and `y`, `x != y`. public func logxor(x : Bool, y : Bool) : Bool { - x != y; + x != y }; /// Returns `not x`. @@ -38,7 +38,7 @@ module { /// Returns the order of `x` and `y`, where `false < true`. public func compare(x : Bool, y : Bool) : { #less; #equal; #greater } { - if (x == y) { #equal } else if (x) { #greater } else { #less }; + if (x == y) { #equal } else if (x) { #greater } else { #less } }; -}; +} diff --git a/src/Buffer.mo b/src/Buffer.mo index f2281676..251ca67c 100644 --- a/src/Buffer.mo +++ b/src/Buffer.mo @@ -57,11 +57,11 @@ module { private func newCapacity(oldCapacity : Nat) : Nat { if (oldCapacity == 0) { - 1; + 1 } else { // calculates ceil(oldCapacity * INCREASE_FACTOR) without floats - ((oldCapacity * INCREASE_FACTOR_NUME) + INCREASE_FACTOR_DENOM - 1) / INCREASE_FACTOR_DENOM; - }; + ((oldCapacity * INCREASE_FACTOR_NUME) + INCREASE_FACTOR_DENOM - 1) / INCREASE_FACTOR_DENOM + } }; public class Buffer(initCapacity : Nat) = this { @@ -98,10 +98,10 @@ module { /// Amortized Space: O(1), Worst Case Space: O(size) public func add(element : X) { if (_size == elements.size()) { - reserve(newCapacity(elements.size())); + reserve(newCapacity(elements.size())) }; elements[_size] := ?element; - _size += 1; + _size += 1 }; /// Returns the element at index `index`. Traps if `index >= size`. Indexing is zero-based. @@ -120,8 +120,8 @@ module { public func get(index : Nat) : X { switch (elements[index]) { case (?element) element; - case null Prim.trap("Buffer index out of bounds in get"); - }; + case null Prim.trap("Buffer index out of bounds in get") + } }; /// Returns the element at index `index` as an option. @@ -141,10 +141,10 @@ module { /// Space: O(1) public func getOpt(index : Nat) : ?X { if (index < _size) { - elements[index]; + elements[index] } else { - null; - }; + null + } }; /// Overwrites the current element at `index` with `element`. Traps if @@ -163,9 +163,9 @@ module { /// Space: O(1) public func put(index : Nat, element : X) { if (index >= _size) { - Prim.trap "Buffer index out of bounds in put"; + Prim.trap "Buffer index out of bounds in put" }; - elements[index] := ?element; + elements[index] := ?element }; /// Removes and returns the last item in the buffer or `null` if @@ -184,7 +184,7 @@ module { /// Amortized Space: O(1), Worst Case Space: O(size) public func removeLast() : ?X { if (_size == 0) { - return null; + return null }; _size -= 1; @@ -194,10 +194,10 @@ module { if (_size < elements.size() / DECREASE_THRESHOLD) { // FIXME should this new capacity be a function of _size // instead of the current capacity? E.g. _size * INCREASE_FACTOR - reserve(elements.size() / DECREASE_FACTOR); + reserve(elements.size() / DECREASE_FACTOR) }; - lastElement; + lastElement }; /// Removes and returns the element at `index` from the buffer. @@ -225,7 +225,7 @@ module { /// Amortized Space: O(1), Worst Case Space: O(size) public func remove(index : Nat) : X { if (index >= _size) { - Prim.trap "Buffer index out of bounds in remove"; + Prim.trap "Buffer index out of bounds in remove" }; let element = elements[index]; @@ -239,34 +239,34 @@ module { label l while (i < _size) { if (i == index) { i += 1; - continue l; + continue l }; elements2[j] := elements[i]; i += 1; - j += 1; + j += 1 }; - elements := elements2; + elements := elements2 } else { // just shift over elements var i = index; while (i < (_size - 1 : Nat)) { elements[i] := elements[i + 1]; - i += 1; + i += 1 }; - elements[_size - 1] := null; + elements[_size - 1] := null }; _size -= 1; switch (element) { case (?element) { - element; + element }; case null { - Prim.trap "Malformed buffer in remove"; - }; - }; + Prim.trap "Malformed buffer in remove" + } + } }; /// Resets the buffer. Capacity is set to 8. @@ -286,7 +286,7 @@ module { /// Space: O(1) public func clear() { _size := 0; - reserve(DEFAULT_CAPACITY); + reserve(DEFAULT_CAPACITY) }; /// Removes all elements from the buffer for which the predicate returns false. @@ -314,17 +314,17 @@ module { switch (elements[i]) { case (?element) { if (predicate(i, element)) { - true; + true } else { numRemoved += 1; - false; - }; + false + } }; case null { - Prim.trap "Malformed buffer in filter()"; - }; - }; - }, + Prim.trap "Malformed buffer in filter()" + } + } + } ); let capacity = elements.size(); @@ -338,13 +338,13 @@ module { if (keep[i]) { elements2[j] := elements[i]; i += 1; - j += 1; + j += 1 } else { - i += 1; - }; + i += 1 + } }; - elements := elements2; + elements := elements2 } else { var i = 0; var j = 0; @@ -352,19 +352,19 @@ module { if (keep[i]) { elements[j] := elements[i]; i += 1; - j += 1; + j += 1 } else { - i += 1; - }; + i += 1 + } }; while (j < _size) { elements[j] := null; - j += 1; - }; + j += 1 + } }; - _size -= numRemoved; + _size -= numRemoved }; /// Returns the capacity of the buffer (the length of the underlying array). @@ -400,7 +400,7 @@ module { /// Space: O(capacity) public func reserve(capacity : Nat) { if (capacity < _size) { - Prim.trap "capacity must be >= size in reserve"; + Prim.trap "capacity must be >= size in reserve" }; let elements2 = Prim.Array_init(capacity, null); @@ -408,9 +408,9 @@ module { var i = 0; while (i < _size) { elements2[i] := elements[i]; - i += 1; + i += 1 }; - elements := elements2; + elements := elements2 }; /// Adds all elements in buffer `b` to this buffer. @@ -434,15 +434,15 @@ module { // Make sure you only allocate a new array at most once if (_size + size2 > elements.size()) { // FIXME would be nice to have a tabulate for var arrays here - reserve(newCapacity(_size + size2)); + reserve(newCapacity(_size + size2)) }; var i = 0; while (i < size2) { elements[_size + i] := buffer2.getOpt i; - i += 1; + i += 1 }; - _size += size2; + _size += size2 }; /// Inserts `element` at `index`, shifts all elements to the right of @@ -462,7 +462,7 @@ module { /// Amortized Space: O(1), Worst Case Space: O(size) public func insert(index : Nat, element : X) { if (index > _size) { - Prim.trap "Buffer index out of bounds in insert"; + Prim.trap "Buffer index out of bounds in insert" }; let capacity = elements.size(); @@ -472,26 +472,26 @@ module { var i = 0; while (i < _size + 1) { if (i < index) { - elements2[i] := elements[i]; + elements2[i] := elements[i] } else if (i == index) { - elements2[i] := ?element; + elements2[i] := ?element } else { - elements2[i] := elements[i - 1]; + elements2[i] := elements[i - 1] }; - i += 1; + i += 1 }; - elements := elements2; + elements := elements2 } else { var i : Nat = _size; while (i > index) { elements[i] := elements[i - 1]; - i -= 1; + i -= 1 }; - elements[index] := ?element; + elements[index] := ?element }; - _size += 1; + _size += 1 }; /// Inserts `buffer2` at `index`, and shifts all elements to the right of @@ -513,7 +513,7 @@ module { /// Amortized Space: O(1), Worst Case Space: O(size1 + size2) public func insertBuffer(index : Nat, buffer2 : Buffer) { if (index > _size) { - Prim.trap "Buffer index out of bounds in insertBuffer"; + Prim.trap "Buffer index out of bounds in insertBuffer" }; let size2 = buffer2.size(); @@ -525,32 +525,32 @@ module { var i = 0; for (element in elements.vals()) { if (i == index) { - i += size2; + i += size2 }; elements2[i] := element; - i += 1; + i += 1 }; i := 0; while (i < size2) { elements2[i + index] := buffer2.getOpt(i); - i += 1; + i += 1 }; - elements := elements2; + elements := elements2 } // just insert else { var i = index; while (i < index + size2) { if (i < _size) { - elements[i + size2] := elements[i]; + elements[i + size2] := elements[i] }; elements[i] := buffer2.getOpt(i - index); - i += 1; - }; + i += 1 + } }; - _size += size2; + _size += size2 }; /// Sorts the elements in the buffer according to `compare`. @@ -573,7 +573,7 @@ module { public func sort(compare : (X, X) -> Order.Order) { // Stable merge sort in a bottom-up iterative style if (_size == 0) { - return; + return }; let scratchSpace = Prim.Array_init(_size, null); @@ -584,10 +584,10 @@ module { var leftStart = 0; // selects the current left subarray being merged while (leftStart < sizeDec) { let mid : Nat = if (leftStart + currSize - 1 : Nat < sizeDec) { - leftStart + currSize - 1; + leftStart + currSize - 1 } else { sizeDec }; let rightEnd : Nat = if (leftStart + (2 * currSize) - 1 : Nat < sizeDec) { - leftStart + (2 * currSize) - 1; + leftStart + (2 * currSize) - 1 } else { sizeDec }; // Merge subarrays elements[leftStart...mid] and elements[mid+1...rightEnd] @@ -602,43 +602,43 @@ module { switch (compare(leftElement, rightElement)) { case (#less or #equal) { scratchSpace[nextSorted] := leftOpt; - left += 1; + left += 1 }; case (#greater) { scratchSpace[nextSorted] := rightOpt; - right += 1; - }; - }; + right += 1 + } + } }; case (_, _) { // only sorting non-null items - Prim.trap "Malformed buffer in sort"; - }; + Prim.trap "Malformed buffer in sort" + } }; - nextSorted += 1; + nextSorted += 1 }; while (left < mid + 1) { scratchSpace[nextSorted] := elements[left]; nextSorted += 1; - left += 1; + left += 1 }; while (right < rightEnd + 1) { scratchSpace[nextSorted] := elements[right]; nextSorted += 1; - right += 1; + right += 1 }; // Copy over merged elements var i = leftStart; while (i < rightEnd + 1) { elements[i] := scratchSpace[i]; - i += 1; + i += 1 }; - leftStart += 2 * currSize; + leftStart += 2 * currSize }; - currSize *= 2; - }; + currSize *= 2 + } }; /// Returns an Iterator (`Iter`) over the elements of this buffer. @@ -667,12 +667,12 @@ module { var nextIndex = 0; public func next() : ?X { if (nextIndex >= _size) { - return null; + return null }; let nextElement = elements[nextIndex]; nextIndex += 1; - nextElement; - }; + nextElement + } }; // FOLLOWING METHODS ARE DEPRECATED @@ -681,9 +681,9 @@ module { public func clone() : Buffer { let newBuffer = Buffer(elements.size()); for (element in vals()) { - newBuffer.add(element); + newBuffer.add(element) }; - newBuffer; + newBuffer }; /// @deprecated Use static library function instead. @@ -691,7 +691,7 @@ module { // immutable clone of array Prim.Array_tabulate( _size, - func(i : Nat) : X { get i }, + func(i : Nat) : X { get i } ); /// @deprecated Use static library function instead. @@ -701,11 +701,11 @@ module { var i = 0; for (element in vals()) { newArray[i] := element; - i += 1; + i += 1 }; - newArray; - }; - }; + newArray + } + } }; /// Returns true iff the buffer is empty. @@ -726,11 +726,11 @@ module { public func contains(buffer : Buffer, element : X, equal : (X, X) -> Bool) : Bool { for (current in buffer.vals()) { if (equal(current, element)) { - return true; - }; + return true + } }; - false; + false }; /// Returns a copy of `buffer`, with the same capacity. @@ -741,9 +741,9 @@ module { public func clone(buffer : Buffer) : Buffer { let newBuffer = Buffer(buffer.capacity()); for (element in buffer.vals()) { - newBuffer.add(element); + newBuffer.add(element) }; - newBuffer; + newBuffer }; /// Finds the greatest element in `buffer` defined by `compare`. @@ -756,20 +756,20 @@ module { /// *Runtime and space assumes that `compare` runs in O(1) time and space. public func max(buffer : Buffer, compare : (X, X) -> Order) : ?X { if (buffer.size() == 0) { - return null; + return null }; var maxSoFar = buffer.get(0); for (current in buffer.vals()) { switch (compare(current, maxSoFar)) { case (#greater) { - maxSoFar := current; + maxSoFar := current }; - case _ {}; - }; + case _ {} + } }; - ?maxSoFar; + ?maxSoFar }; /// Finds the least element in `buffer` defined by `compare`. @@ -782,20 +782,20 @@ module { /// *Runtime and space assumes that `compare` runs in O(1) time and space. public func min(buffer : Buffer, compare : (X, X) -> Order) : ?X { if (buffer.size() == 0) { - return null; + return null }; var minSoFar = buffer.get(0); for (current in buffer.vals()) { switch (compare(current, minSoFar)) { case (#less) { - minSoFar := current; + minSoFar := current }; - case _ {}; - }; + case _ {} + } }; - ?minSoFar; + ?minSoFar }; /// Defines equality for two buffers, using `equal` to recursively compare elements in the @@ -812,18 +812,18 @@ module { let size1 = buffer1.size(); if (size1 != buffer2.size()) { - return false; + return false }; var i = 0; while (i < size1) { if (not equal(buffer1.get(i), buffer2.get(i))) { - return false; + return false }; - i += 1; + i += 1 }; - true; + true }; /// Defines comparison for two buffers, using `compare` to recursively compare elements in the @@ -843,23 +843,23 @@ module { while (i < minSize) { switch (compare(buffer1.get(i), buffer2.get(i))) { case (#less) { - return #less; + return #less }; case (#greater) { - return #greater; + return #greater }; - case _ {}; + case _ {} }; - i += 1; + i += 1 }; if (size1 < size2) { - #less; + #less } else if (size1 == size2) { - #equal; + #equal } else { - #greater; - }; + #greater + } }; /// Creates a textual representation of `buffer`, using `toText` to recursively @@ -876,14 +876,14 @@ module { var text = ""; while (i < size - 1) { text := text # toText(buffer.get(i)) # ", "; // Text implemented as rope - i += 1; + i += 1 }; if (size > 0) { // avoid the trailing comma - text := text # toText(buffer.get(i)); + text := text # toText(buffer.get(i)) }; - "[" # text # "]"; + "[" # text # "]" }; /// Hashes `buffer` using `hash` to hash the underlying elements. @@ -902,10 +902,10 @@ module { while (i < size) { accHash := Prim.intToNat32Wrap(i) ^ accHash ^ hash(buffer.get(i)); - i += 1; + i += 1 }; - accHash; + accHash }; /// Finds the first index of `element` in `buffer` using equality of elements defined @@ -921,12 +921,12 @@ module { var i = 0; while (i < size) { if (equal(buffer.get(i), element)) { - return ?i; + return ?i }; - i += 1; + i += 1 }; - null; + null }; /// Finds the last index of `element` in `buffer` using equality of elements defined @@ -940,17 +940,17 @@ module { public func lastIndexOf(element : X, buffer : Buffer, equal : (X, X) -> Bool) : ?Nat { let size = buffer.size(); if (size == 0) { - return null; + return null }; var i = size; while (i >= 1) { i -= 1; if (equal(buffer.get(i), element)) { - return ?i; - }; + return ?i + } }; - null; + null }; /// Searches for `subBuffer` in `buffer`, and returns the starting index if it is found. @@ -966,7 +966,7 @@ module { let size = buffer.size(); let subSize = subBuffer.size(); if (subSize > size or subSize == 0) { - return null; + return null }; // precompute lps @@ -978,13 +978,13 @@ module { if (equal(subBuffer.get(i), subBuffer.get(j))) { i += 1; lps[j] := i; - j += 1; + j += 1 } else if (i == 0) { lps[j] := 0; - j += 1; + j += 1 } else { - i := lps[i - 1]; - }; + i := lps[i - 1] + } }; // start search @@ -993,20 +993,20 @@ module { let subSizeDec = subSize - 1 : Nat; // hoisting loop invariant while (i < subSize and j < size) { if (equal(subBuffer.get(i), buffer.get(j)) and i == subSizeDec) { - return ?(j - i); + return ?(j - i) } else if (equal(subBuffer.get(i), buffer.get(j))) { i += 1; - j += 1; + j += 1 } else { if (i != 0) { - i := lps[i - 1]; + i := lps[i - 1] } else { - j += 1; - }; - }; + j += 1 + } + } }; - null; + null }; /// Similar to indexOf, but runs in logarithmic time. Assumes that `buffer` is sorted. @@ -1027,18 +1027,18 @@ module { let current = buffer.get(mid); switch (compare(element, current)) { case (#equal) { - return ?mid; + return ?mid }; case (#less) { - high := mid; + high := mid }; case (#greater) { - low := mid + 1; - }; - }; + low := mid + 1 + } + } }; - null; + null }; /// Returns the sub-buffer of `buffer` starting at index `start` @@ -1052,7 +1052,7 @@ module { let size = buffer.size(); let end = start + length; // exclusive if (start >= size or end > size) { - Prim.trap "Buffer index out of bounds in subBuffer"; + Prim.trap "Buffer index out of bounds in subBuffer" }; let newBuffer = Buffer(newCapacity length); @@ -1061,10 +1061,10 @@ module { while (i < end) { newBuffer.add(buffer.get(i)); - i += 1; + i += 1 }; - newBuffer; + newBuffer }; /// Checks if `subBuffer` is a sub-Buffer of `buffer`. Uses `equal` to @@ -1078,8 +1078,8 @@ module { public func isSubBufferOf(subBuffer : Buffer, buffer : Buffer, equal : (X, X) -> Bool) : Bool { switch (indexOfBuffer(subBuffer, buffer, equal)) { case null subBuffer.size() == 0; - case _ true; - }; + case _ true + } }; /// Checks if `subBuffer` is a strict subBuffer of `buffer`, i.e. `subBuffer` must be @@ -1099,9 +1099,9 @@ module { index != 0 and index != (buffer.size() - subBufferSize : Nat) // enforce strictness }; case null { - subBufferSize == 0 and subBufferSize != buffer.size(); - }; - }; + subBufferSize == 0 and subBufferSize != buffer.size() + } + } }; /// Returns the prefix of `buffer` of length `length`. Traps if `length` @@ -1113,7 +1113,7 @@ module { public func prefix(buffer : Buffer, length : Nat) : Buffer { let size = buffer.size(); if (length > size) { - Prim.trap "Buffer index out of bounds in prefix"; + Prim.trap "Buffer index out of bounds in prefix" }; let newBuffer = Buffer(newCapacity length); @@ -1121,10 +1121,10 @@ module { var i = 0; while (i < length) { newBuffer.add(buffer.get(i)); - i += 1; + i += 1 }; - newBuffer; + newBuffer }; /// Checks if `prefix` is a prefix of `buffer`. Uses `equal` to @@ -1138,19 +1138,19 @@ module { public func isPrefixOf(prefix : Buffer, buffer : Buffer, equal : (X, X) -> Bool) : Bool { let sizePrefix = prefix.size(); if (buffer.size() < sizePrefix) { - return false; + return false }; var i = 0; while (i < sizePrefix) { if (not equal(buffer.get(i), prefix.get(i))) { - return false; + return false }; - i += 1; + i += 1 }; - return true; + return true }; /// Checks if `prefix` is a strict prefix of `buffer`. Uses `equal` to @@ -1163,9 +1163,9 @@ module { /// *Runtime and space assumes that `equal` runs in O(1) time and space. public func isStrictPrefixOf(prefix : Buffer, buffer : Buffer, equal : (X, X) -> Bool) : Bool { if (buffer.size() <= prefix.size()) { - return false; + return false }; - isPrefixOf(prefix, buffer, equal); + isPrefixOf(prefix, buffer, equal) }; /// Returns the suffix of `buffer` of length `length`. @@ -1178,7 +1178,7 @@ module { let size = buffer.size(); if (length > size) { - Prim.trap "Buffer index out of bounds in suffix"; + Prim.trap "Buffer index out of bounds in suffix" }; let newBuffer = Buffer(newCapacity length); @@ -1187,10 +1187,10 @@ module { while (i < size) { newBuffer.add(buffer.get(i)); - i += 1; + i += 1 }; - newBuffer; + newBuffer }; /// Checks if `suffix` is a suffix of `buffer`. Uses `equal` to compare @@ -1205,7 +1205,7 @@ module { let suffixSize = suffix.size(); let bufferSize = buffer.size(); if (bufferSize < suffixSize) { - return false; + return false }; var i = bufferSize; @@ -1214,11 +1214,11 @@ module { i -= 1; j -= 1; if (not equal(buffer.get(i), suffix.get(j))) { - return false; - }; + return false + } }; - return true; + return true }; /// Checks if `suffix` is a strict suffix of `buffer`. Uses `equal` to compare @@ -1231,9 +1231,9 @@ module { /// *Runtime and space assumes that `equal` runs in O(1) time and space. public func isStrictSuffixOf(suffix : Buffer, buffer : Buffer, equal : (X, X) -> Bool) : Bool { if (buffer.size() <= suffix.size()) { - return false; + return false }; - isSuffixOf(suffix, buffer, equal); + isSuffixOf(suffix, buffer, equal) }; /// Returns true iff every element in `buffer` satisfies `predicate`. @@ -1246,11 +1246,11 @@ module { public func forAll(buffer : Buffer, predicate : X -> Bool) : Bool { for (element in buffer.vals()) { if (not predicate element) { - return false; - }; + return false + } }; - true; + true }; /// Returns true iff some element in `buffer` satisfies `predicate`. @@ -1263,11 +1263,11 @@ module { public func forSome(buffer : Buffer, predicate : X -> Bool) : Bool { for (element in buffer.vals()) { if (predicate element) { - return true; - }; + return true + } }; - false; + false }; /// Returns true iff no element in `buffer` satisfies `predicate`. @@ -1280,11 +1280,11 @@ module { public func forNone(buffer : Buffer, predicate : X -> Bool) : Bool { for (element in buffer.vals()) { if (predicate element) { - return false; - }; + return false + } }; - true; + true }; /// Creates an array containing elements from `buffer`. @@ -1296,7 +1296,7 @@ module { // immutable clone of array Prim.Array_tabulate( buffer.size(), - func(i : Nat) : X { buffer.get(i) }, + func(i : Nat) : X { buffer.get(i) } ); /// Creates a mutable array containing elements from `buffer`. @@ -1311,10 +1311,10 @@ module { var i = 1; while (i < size) { newArray[i] := buffer.get(i); - i += 1; + i += 1 }; - newArray; - }; + newArray + } }; /// Creates a buffer containing elements from `array`. @@ -1333,10 +1333,10 @@ module { let newBuffer = Buffer(newCapacity(array.size())); for (element in array.vals()) { - newBuffer.add(element); + newBuffer.add(element) }; - newBuffer; + newBuffer }; /// Creates a buffer containing elements from `array`. @@ -1348,10 +1348,10 @@ module { let newBuffer = Buffer(newCapacity(array.size())); for (element in array.vals()) { - newBuffer.add(element); + newBuffer.add(element) }; - newBuffer; + newBuffer }; /// Creates a buffer containing elements from `iter`. @@ -1363,10 +1363,10 @@ module { let newBuffer = Buffer(DEFAULT_CAPACITY); // can't get size from `iter` for (element in iter) { - newBuffer.add(element); + newBuffer.add(element) }; - newBuffer; + newBuffer }; /// Reallocates the array underlying `buffer` such that capacity == size. @@ -1377,8 +1377,8 @@ module { public func trimToSize(buffer : Buffer) { let size = buffer.size(); if (size < buffer.capacity()) { - buffer.reserve(size); - }; + buffer.reserve(size) + } }; /// Creates a new buffer by applying `f` to each element in `buffer`. @@ -1392,10 +1392,10 @@ module { let newBuffer = Buffer(buffer.capacity()); for (element in buffer.vals()) { - newBuffer.add(f element); + newBuffer.add(f element) }; - newBuffer; + newBuffer }; /// Applies `f` to each element in `buffer`. @@ -1407,8 +1407,8 @@ module { /// *Runtime and space assumes that `f` runs in O(1) time and space. public func iterate(buffer : Buffer, f : X -> ()) { for (element in buffer.vals()) { - f element; - }; + f element + } }; /// Applies `f` to each element in `buffer` and its index. @@ -1425,10 +1425,10 @@ module { let size = buffer.size(); while (i < size) { newBuffer.add(f(i, buffer.get(i))); - i += 1; + i += 1 }; - newBuffer; + newBuffer }; /// Creates a new buffer by applying `f` to each element in `buffer`, @@ -1445,13 +1445,13 @@ module { for (element in buffer.vals()) { switch (f element) { case (?element) { - newBuffer.add(element); + newBuffer.add(element) }; - case _ {}; - }; + case _ {} + } }; - newBuffer; + newBuffer }; /// Creates a new buffer by applying `f` to each element in `buffer`. @@ -1469,15 +1469,15 @@ module { for (element in buffer.vals()) { switch (f element) { case (#ok result) { - newBuffer.add(result); + newBuffer.add(result) }; case (#err e) { - return #err e; - }; - }; + return #err e + } + } }; - #ok newBuffer; + #ok newBuffer }; /// Creates a new buffer by applying `k` to each element in `buffer`, @@ -1493,10 +1493,10 @@ module { let newBuffer = Buffer(buffer.size() * 4); for (element in buffer.vals()) { - newBuffer.append(k element); + newBuffer.append(k element) }; - newBuffer; + newBuffer }; /// Collapses the elements in `buffer` into a single value by starting with `base` @@ -1512,10 +1512,10 @@ module { var accumulation = base; for (element in buffer.vals()) { - accumulation := combine(accumulation, element); + accumulation := combine(accumulation, element) }; - accumulation; + accumulation }; /// Collapses the elements in `buffer` into a single value by starting with `base` @@ -1530,17 +1530,17 @@ module { public func foldRight(buffer : Buffer, base : A, combine : (X, A) -> A) : A { let size = buffer.size(); if (size == 0) { - return base; + return base }; var accumulation = base; var i = size; while (i >= 1) { i -= 1; // to avoid Nat underflow, subtract first and stop iteration at 1 - accumulation := combine(buffer.get(i), accumulation); + accumulation := combine(buffer.get(i), accumulation) }; - accumulation; + accumulation }; /// Returns the first element of `buffer`. Traps if `buffer` is empty. @@ -1565,7 +1565,7 @@ module { public func make(element : X) : Buffer { let newBuffer = Buffer(1); newBuffer.add(element); - newBuffer; + newBuffer }; /// Reverses the order of elements in `buffer`. @@ -1576,7 +1576,7 @@ module { public func reverse(buffer : Buffer) { let size = buffer.size(); if (size == 0) { - return; + return }; var i = 0; @@ -1587,8 +1587,8 @@ module { buffer.put(j, buffer.get(i)); buffer.put(i, temp); i += 1; - j -= 1; - }; + j -= 1 + } }; /// Merges two sorted buffers into a single sorted buffer, using `compare` to define @@ -1616,26 +1616,26 @@ module { switch (compare(current1, current2)) { case (#less) { newBuffer.add(current1); - pointer1 += 1; + pointer1 += 1 }; case _ { newBuffer.add(current2); - pointer2 += 1; - }; - }; + pointer2 += 1 + } + } }; while (pointer1 < size1) { newBuffer.add(buffer1.get(pointer1)); - pointer1 += 1; + pointer1 += 1 }; while (pointer2 < size2) { newBuffer.add(buffer2.get(pointer2)); - pointer2 += 1; + pointer2 += 1 }; - newBuffer; + newBuffer }; /// Eliminates all duplicate elements in `buffer` as defined by `compare`. @@ -1664,38 +1664,38 @@ module { switch (compare(pair1.1, pair2.1)) { case (#equal) { if (pair2.0 < pair1.0) { - minIndex := pair2; + minIndex := pair2 }; - j += 1; + j += 1 }; case _ { - break duplicates; - }; - }; + break duplicates + } + } }; uniques.add(minIndex); - i := j + 1; + i := j + 1 }; // resort based on original ordering and place back in buffer uniques.sort( func(pair1, pair2) { if (pair1.0 < pair2.0) { - #less; + #less } else if (pair1.0 == pair2.0) { - #equal; + #equal } else { - #greater; - }; - }, + #greater + } + } ); buffer.clear(); buffer.reserve(uniques.size()); for (element in uniques.vals()) { - buffer.add(element.1); - }; + buffer.add(element.1) + } }; /// Splits `buffer` into a pair of buffers where all elements in the left @@ -1713,13 +1713,13 @@ module { for (element in buffer.vals()) { if (predicate element) { - trueBuffer.add(element); + trueBuffer.add(element) } else { - falseBuffer.add(element); - }; + falseBuffer.add(element) + } }; - (trueBuffer, falseBuffer); + (trueBuffer, falseBuffer) }; /// Splits the buffer into two buffers at `index`, where the left buffer contains @@ -1736,7 +1736,7 @@ module { let size = buffer.size(); if (index < 0 or index > size) { - Prim.trap "Index out of bounds in split"; + Prim.trap "Index out of bounds in split" }; let buffer1 = Buffer(newCapacity index); @@ -1745,14 +1745,14 @@ module { var i = 0; while (i < index) { buffer1.add(buffer.get(i)); - i += 1; + i += 1 }; while (i < size) { buffer2.add(buffer.get(i)); - i += 1; + i += 1 }; - (buffer1, buffer2); + (buffer1, buffer2) }; /// Breaks up `buffer` into buffers of size `size`. The last chunk may @@ -1764,7 +1764,7 @@ module { /// Space: O(number of elements in buffer) public func chunk(buffer : Buffer, size : Nat) : Buffer> { if (size == 0) { - Prim.trap "Chunk size must be non-zero in chunk"; + Prim.trap "Chunk size must be non-zero in chunk" }; // ceil(buffer.size() / size) @@ -1776,16 +1776,16 @@ module { if (innerSize == size) { newBuffer.add(newInnerBuffer); newInnerBuffer := Buffer(newCapacity size); - innerSize := 0; + innerSize := 0 }; newInnerBuffer.add(element); - innerSize += 1; + innerSize += 1 }; if (innerSize > 0) { - newBuffer.add(newInnerBuffer); + newBuffer.add(newInnerBuffer) }; - newBuffer; + newBuffer }; /// Groups equal and adjacent elements in the list into sub lists. @@ -1799,7 +1799,7 @@ module { let size = buffer.size(); let newBuffer = Buffer>(size); if (size == 0) { - return newBuffer; + return newBuffer }; var i = 0; @@ -1809,20 +1809,20 @@ module { let element = buffer.get(i); if (equal(baseElement, element)) { - newInnerBuffer.add(element); + newInnerBuffer.add(element) } else { newBuffer.add(newInnerBuffer); baseElement := element; newInnerBuffer := Buffer(size - i); - newInnerBuffer.add(element); + newInnerBuffer.add(element) }; - i += 1; + i += 1 }; if (newInnerBuffer.size() > 0) { - newBuffer.add(newInnerBuffer); + newBuffer.add(newInnerBuffer) }; - newBuffer; + newBuffer }; /// Flattens the buffer of buffers into a single buffer. @@ -1833,24 +1833,24 @@ module { public func flatten(buffer : Buffer>) : Buffer { let size = buffer.size(); if (size == 0) { - return Buffer(0); + return Buffer(0) }; let newBuffer = Buffer( if (buffer.get(0).size() != 0) { - newCapacity(buffer.get(0).size() * size); + newCapacity(buffer.get(0).size() * size) } else { - newCapacity(size); - }, + newCapacity(size) + } ); for (innerBuffer in buffer.vals()) { for (innerElement in innerBuffer.vals()) { - newBuffer.add(innerElement); - }; + newBuffer.add(innerElement) + } }; - newBuffer; + newBuffer }; /// Combines the two buffers into a single buffer of pairs, pairing together @@ -1862,7 +1862,7 @@ module { /// Space: O(min(size1, size2)) public func zip(buffer1 : Buffer, buffer2 : Buffer) : Buffer<(X, Y)> { // compiler should pull lamda out as a static function since it is fully closed - zipWith(buffer1, buffer2, func(x, y) = (x, y)); + zipWith(buffer1, buffer2, func(x, y) = (x, y)) }; /// Combines the two buffers into a single buffer, pairing together @@ -1884,9 +1884,9 @@ module { let newBuffer = Buffer(newCapacity minSize); while (i < minSize) { newBuffer.add(zip(buffer1.get(i), buffer2.get(i))); - i += 1; + i += 1 }; - newBuffer; + newBuffer }; /// Creates a new buffer taking elements in order from `buffer` until predicate @@ -1902,12 +1902,12 @@ module { for (element in buffer.vals()) { if (not predicate element) { - return newBuffer; + return newBuffer }; - newBuffer.add(element); + newBuffer.add(element) }; - newBuffer; + newBuffer }; /// Creates a new buffer excluding elements in order from `buffer` until predicate @@ -1926,12 +1926,12 @@ module { var take = false; label iter for (element in buffer.vals()) { if (not (take or predicate element)) { - take := true; + take := true }; if (take) { - newBuffer.add(element); - }; + newBuffer.add(element) + } }; - newBuffer; - }; -}; + newBuffer + } +} diff --git a/src/CertifiedData.mo b/src/CertifiedData.mo index b66ba498..6442c369 100644 --- a/src/CertifiedData.mo +++ b/src/CertifiedData.mo @@ -26,4 +26,4 @@ module { /// when processing a query call. public let getCertificate : () -> ?Blob = Prim.getCertificate; -}; +} diff --git a/src/Char.mo b/src/Char.mo index 94b3d817..d4ef02fc 100644 --- a/src/Char.mo +++ b/src/Char.mo @@ -24,7 +24,7 @@ module { /// Returns `true` when `c` is a decimal digit between `0` and `9`, otherwise `false`. public func isDigit(c : Char) : Bool { - Prim.charToNat32(c) -% Prim.charToNat32('0') <= (9 : Nat32); + Prim.charToNat32(c) -% Prim.charToNat32('0') <= (9 : Nat32) }; /// Returns the Unicode _White_Space_ property of `c`. @@ -59,7 +59,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Char, y : Char) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; -}; +} diff --git a/src/Debug.mo b/src/Debug.mo index 33f26ba6..f104e2c1 100644 --- a/src/Debug.mo +++ b/src/Debug.mo @@ -11,4 +11,4 @@ module { /// `trap(t)` traps execution with a user-provided message. public let trap : Text -> None = Prim.trap; -}; +} diff --git a/src/Deque.mo b/src/Deque.mo index f1257b68..4de102b0 100644 --- a/src/Deque.mo +++ b/src/Deque.mo @@ -15,27 +15,27 @@ module { /// True when the queue is empty public func isEmpty(q : Deque) : Bool { switch q { - case (f, r) { List.isNil(f) and List.isNil(r) }; - }; + case (f, r) { List.isNil(f) and List.isNil(r) } + } }; func check(q : Deque) : Deque { switch q { case (null, r) { let (a, b) = List.split(List.size(r) / 2, r); - (List.reverse(b), a); + (List.reverse(b), a) }; case (f, null) { let (a, b) = List.split(List.size(f) / 2, f); - (a, List.reverse(b)); + (a, List.reverse(b)) }; - case q { q }; - }; + case q { q } + } }; /// Insert a new element on the front end of the queue public func pushFront(q : Deque, x : T) : Deque { - check(List.push(x, q.0), q.1); + check(List.push(x, q.0), q.1) }; /// Inspect the (optional) first element on the front end of the queue @@ -43,8 +43,8 @@ module { switch q { case (?(x, f), r) { ?x }; case (null, ?(x, r)) { ?x }; - case _ { null }; - }; + case _ { null } + } }; /// Remove the first element on the front end of the queue; Returns null when empty. @@ -52,13 +52,13 @@ module { switch q { case (?(x, f), r) { ?(x, check(f, r)) }; case (null, ?(x, r)) { ?(x, check(null, r)) }; - case _ { null }; - }; + case _ { null } + } }; /// Insert a new element on the back end of the queue public func pushBack(q : Deque, x : T) : Deque { - check(q.0, List.push(x, q.1)); + check(q.0, List.push(x, q.1)) }; /// Inspect the (optional) first element on the back end of the queue @@ -66,8 +66,8 @@ module { switch q { case (f, ?(x, r)) { ?x }; case (?(x, r), null) { ?x }; - case _ { null }; - }; + case _ { null } + } }; /// Remove the first element on the back end of the queue; Returns null when empty. @@ -75,7 +75,7 @@ module { switch q { case (f, ?(x, r)) { ?(check(f, r), x) }; case (?(x, f), null) { ?(check(f, null), x) }; - case _ { null }; - }; - }; -}; + case _ { null } + } + } +} diff --git a/src/Error.mo b/src/Error.mo index 439ae35b..0a7dcec1 100644 --- a/src/Error.mo +++ b/src/Error.mo @@ -38,4 +38,4 @@ module { /// Returns the message of an error `e`. public let message : (e : Error) -> Text = Prim.errorMessage; -}; +} diff --git a/src/ExperimentalCycles.mo b/src/ExperimentalCycles.mo index 320fc15c..9979a9c0 100644 --- a/src/ExperimentalCycles.mo +++ b/src/ExperimentalCycles.mo @@ -48,4 +48,4 @@ module { /// whether or not `refunded` is used to observe them. public let refunded : () -> (amount : Nat) = Prim.cyclesRefunded; -}; +} diff --git a/src/ExperimentalInternetComputer.mo b/src/ExperimentalInternetComputer.mo index 9d94cd6f..f8eb715f 100644 --- a/src/ExperimentalInternetComputer.mo +++ b/src/ExperimentalInternetComputer.mo @@ -29,7 +29,7 @@ module { let post = Prim.performanceCounter(0); // performance_counter costs around 200 extra instructions, we perform an empty measurement to decide the overhead let overhead = pre - init; - post - pre - overhead; + post - pre - overhead } -}; +} diff --git a/src/ExperimentalStableMemory.mo b/src/ExperimentalStableMemory.mo index e9c6dcf5..d7c2c154 100644 --- a/src/ExperimentalStableMemory.mo +++ b/src/ExperimentalStableMemory.mo @@ -95,4 +95,4 @@ module { /// Traps on out-of-bounds access. public let storeBlob : (offset : Nat64, value : Blob) -> () = Prim.stableMemoryStoreBlob; -}; +} diff --git a/src/Float.mo b/src/Float.mo index 5f27f923..ebc88e4d 100644 --- a/src/Float.mo +++ b/src/Float.mo @@ -81,7 +81,7 @@ module { case (#exp(prec)) { Prim.floatToFormattedText(x, prec, 1) }; case (#gen(prec)) { Prim.floatToFormattedText(x, prec, 2) }; case (#hex(prec)) { Prim.floatToFormattedText(x, prec, 3) }; - case (#exact) { Prim.floatToFormattedText(x, 17, 2) }; + case (#exact) { Prim.floatToFormattedText(x, 17, 2) } }; /// Conversion to Text. Use `format(fmt, x)` for more detailed control. @@ -119,7 +119,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Float, y : Float) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the negation of `x`, `-x` . @@ -143,4 +143,4 @@ module { /// Returns `x` to the power of `y`, `x ** y`. public func pow(x : Float, y : Float) : Float { x ** y }; -}; +} diff --git a/src/Func.mo b/src/Func.mo index 9f8c3007..34cd189d 100644 --- a/src/Func.mo +++ b/src/Func.mo @@ -12,8 +12,8 @@ module { /// ``` public func compose(f : B -> C, g : A -> B) : A -> C { func(x : A) : C { - f(g(x)); - }; + f(g(x)) + } }; /// The `identity` function returns its argument. @@ -33,5 +33,5 @@ module { /// assert(Func.const(10)("hello") == 10); /// assert(Func.const(true)(20) == true); /// ``` - public func const(x : A) : B -> A = func(_) = x; -}; + public func const(x : A) : B -> A = func(_) = x +} diff --git a/src/Hash.mo b/src/Hash.mo index 3eee0e03..285c02b6 100644 --- a/src/Hash.mo +++ b/src/Hash.mo @@ -14,12 +14,12 @@ module { /// Project a given bit from the bit vector. public func bit(h : Hash, pos : Nat) : Bool { assert (pos <= length); - (h & (Prim.natToNat32(1) << Prim.natToNat32(pos))) != Prim.natToNat32(0); + (h & (Prim.natToNat32(1) << Prim.natToNat32(pos))) != Prim.natToNat32(0) }; /// Test if two hashes are equal public func equal(ha : Hash, hb : Hash) : Bool { - ha == hb; + ha == hb }; /// Computes a hash from the least significant 32-bits of `n`, ignoring other bits. @@ -30,30 +30,30 @@ module { j & (255 << 0), j & (255 << 8), j & (255 << 16), - j & (255 << 24), - ]); + j & (255 << 24) + ]) }; /// @deprecated This function will be removed in future. public func debugPrintBits(bits : Hash) { for (j in Iter.range(0, length - 1)) { if (bit(bits, j)) { - Prim.debugPrint("1"); + Prim.debugPrint("1") } else { - Prim.debugPrint("0"); - }; - }; + Prim.debugPrint("0") + } + } }; /// @deprecated This function will be removed in future. public func debugPrintBitsRev(bits : Hash) { for (j in Iter.revRange(length - 1, 0)) { if (bit(bits, Prim.abs(j))) { - Prim.debugPrint("1"); + Prim.debugPrint("1") } else { - Prim.debugPrint("0"); - }; - }; + Prim.debugPrint("0") + } + } }; /// Jenkin's one at a time: @@ -71,12 +71,12 @@ module { for (natOfKey in key.vals()) { hash := hash +% natOfKey; hash := hash +% hash << 10; - hash := hash ^ (hash >> 6); + hash := hash ^ (hash >> 6) }; hash := hash +% hash << 3; hash := hash ^ (hash >> 11); hash := hash +% hash << 15; - return hash; + return hash }; -}; +} diff --git a/src/HashMap.mo b/src/HashMap.mo index 382c5d1f..77fe95c5 100644 --- a/src/HashMap.mo +++ b/src/HashMap.mo @@ -32,7 +32,7 @@ module { public class HashMap( initCapacity : Nat, keyEq : (K, K) -> Bool, - keyHash : K -> Hash.Hash, + keyHash : K -> Hash.Hash ) { var table : [var KVs] = [var]; @@ -48,7 +48,7 @@ module { func keyHash_(k : K) : Key = (keyHash(k), k); func keyHashEq(k1 : Key, k2 : Key) : Bool { - k1.0 == k2.0 and keyEq(k1.1, k2.1); + k1.0 == k2.0 and keyEq(k1.1, k2.1) }; /// Removes the entry with the key `k` and returns the associated value if it @@ -62,12 +62,12 @@ module { table[pos] := kvs2; switch (ov) { case null {}; - case _ { _count -= 1 }; + case _ { _count -= 1 } }; - ov; + ov } else { - null; - }; + null + } }; /// Gets the entry with the key `k` and returns its associated value if it @@ -76,10 +76,10 @@ module { let h = Prim.nat32ToNat(keyHash(k)); let m = table.size(); let v = if (m > 0) { - AssocList.find, V>(table[h % m], keyHash_(k), keyHashEq); + AssocList.find, V>(table[h % m], keyHash_(k), keyHashEq) } else { - null; - }; + null + } }; /// Insert the value `v` at key `k`. Overwrites an existing entry with key `k` @@ -91,12 +91,12 @@ module { if (_count >= table.size()) { let size = if (_count == 0) { if (initCapacity > 0) { - initCapacity; + initCapacity } else { - 1; - }; + 1 + } } else { - table.size() * 2; + table.size() * 2 }; let table2 = A.init>(size, null); for (i in table.keys()) { @@ -107,12 +107,12 @@ module { case (?((k, v), kvsTail)) { let pos2 = Nat32.toNat(k.0) % table2.size(); // critical: uses saved hash. no re-hash. table2[pos2] := ?((k, v), table2[pos2]); - kvs := kvsTail; - }; - }; - }; + kvs := kvsTail + } + } + } }; - table := table2; + table := table2 }; let h = Prim.nat32ToNat(keyHash(k)); let pos = h % table.size(); @@ -120,26 +120,26 @@ module { table[pos] := kvs2; switch (ov) { case null { _count += 1 }; - case _ {}; + case _ {} }; - ov; + ov }; /// An `Iter` over the keys. public func keys() : Iter.Iter { - Iter.map(entries(), func(kv : (K, V)) : K { kv.0 }); + Iter.map(entries(), func(kv : (K, V)) : K { kv.0 }) }; /// An `Iter` over the values. public func vals() : Iter.Iter { - Iter.map(entries(), func(kv : (K, V)) : V { kv.1 }); + Iter.map(entries(), func(kv : (K, V)) : V { kv.1 }) }; /// Returns an iterator over the key value pairs in this /// `HashMap`. Does _not_ modify the `HashMap`. public func entries() : Iter.Iter<(K, V)> { if (table.size() == 0) { - object { public func next() : ?(K, V) { null } }; + object { public func next() : ?(K, V) { null } } } else { object { var kvs = table[0]; @@ -148,21 +148,21 @@ module { switch kvs { case (?(kv, kvs2)) { kvs := kvs2; - ?(kv.0.1, kv.1); + ?(kv.0.1, kv.1) }; case null { if (nextTablePos < table.size()) { kvs := table[nextTablePos]; nextTablePos += 1; - next(); + next() } else { - null; - }; - }; - }; - }; - }; - }; + null + } + } + } + } + } + } }; }; @@ -172,13 +172,13 @@ module { public func clone( h : HashMap, keyEq : (K, K) -> Bool, - keyHash : K -> Hash.Hash, + keyHash : K -> Hash.Hash ) : HashMap { let h2 = HashMap(h.size(), keyEq, keyHash); for ((k, v) in h.entries()) { - h2.put(k, v); + h2.put(k, v) }; - h2; + h2 }; /// Clone from any iterator of key-value pairs @@ -186,45 +186,45 @@ module { iter : Iter.Iter<(K, V)>, initCapacity : Nat, keyEq : (K, K) -> Bool, - keyHash : K -> Hash.Hash, + keyHash : K -> Hash.Hash ) : HashMap { let h = HashMap(initCapacity, keyEq, keyHash); for ((k, v) in iter) { - h.put(k, v); + h.put(k, v) }; - h; + h }; public func map( h : HashMap, keyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash, - mapFn : (K, V1) -> V2, + mapFn : (K, V1) -> V2 ) : HashMap { let h2 = HashMap(h.size(), keyEq, keyHash); for ((k, v1) in h.entries()) { let v2 = mapFn(k, v1); - h2.put(k, v2); + h2.put(k, v2) }; - h2; + h2 }; public func mapFilter( h : HashMap, keyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash, - mapFn : (K, V1) -> ?V2, + mapFn : (K, V1) -> ?V2 ) : HashMap { let h2 = HashMap(h.size(), keyEq, keyHash); for ((k, v1) in h.entries()) { switch (mapFn(k, v1)) { case null {}; case (?v2) { - h2.put(k, v2); - }; - }; + h2.put(k, v2) + } + } }; - h2; + h2 }; -}; +} diff --git a/src/Heap.mo b/src/Heap.mo index f468c2d9..d779ca3c 100644 --- a/src/Heap.mo +++ b/src/Heap.mo @@ -16,33 +16,33 @@ module { /// Get purely-functional representation public func share() : Tree { - heap; + heap }; /// Put purely-functional representation into class. Need to make sure the tree is constructed with the same compare function public func unsafeUnshare(t : Tree) { - heap := t; + heap := t }; /// Insert an element to the heap public func put(x : T) { - heap := merge(heap, ?(1, x, null, null), ord); + heap := merge(heap, ?(1, x, null, null), ord) }; /// Return the minimal element public func peekMin() : ?T { switch heap { case (null) { null }; - case (?(_, x, _, _)) { ?x }; - }; + case (?(_, x, _, _)) { ?x } + } }; /// Delete the minimal element public func deleteMin() { switch heap { case null {}; - case (?(_, _, a, b)) { heap := merge(a, b, ord) }; - }; + case (?(_, _, a, b)) { heap := merge(a, b, ord) } + } }; /// Remove the minimal element and return its value @@ -51,25 +51,25 @@ module { case null { null }; case (?(_, x, a, b)) { heap := merge(a, b, ord); - ?x; - }; - }; - }; + ?x + } + } + } }; func rank(heap : Tree) : Int { switch heap { case null { 0 }; - case (?(r, _, _, _)) { r }; - }; + case (?(r, _, _, _)) { r } + } }; func makeT(x : T, a : Tree, b : Tree) : Tree { if (rank(a) >= rank(b)) { - ?(rank(b) + 1, x, a, b); + ?(rank(b) + 1, x, a, b) } else { - ?(rank(a) + 1, x, b, a); - }; + ?(rank(a) + 1, x, b, a) + } }; func merge(h1 : Tree, h2 : Tree, ord : (T, T) -> O.Order) : Tree { @@ -79,10 +79,10 @@ module { case (?(_, x, a, b), ?(_, y, c, d)) { switch (ord(x, y)) { case (#less) { makeT(x, a, merge(b, h2, ord)) }; - case _ { makeT(y, c, merge(d, h1, ord)) }; - }; - }; - }; + case _ { makeT(y, c, merge(d, h1, ord)) } + } + } + } }; /// Convert iterator into a heap in O(N) time. @@ -93,21 +93,21 @@ module { switch (xs) { case (null) { null }; case (?(hd, null)) { ?(hd, null) }; - case (?(h1, ?(h2, tl))) { ?(merge(h1, h2, ord), join(tl)) }; - }; + case (?(h1, ?(h2, tl))) { ?(merge(h1, h2, ord), join(tl)) } + } }; switch (xs) { case null { P.unreachable() }; case (?(hd, null)) { hd }; - case _ { build(join(xs)) }; - }; + case _ { build(join(xs)) } + } }; let list = I.toList(I.map(iter, func(x : T) : Tree { ?(1, x, null, null) })); if (not L.isNil(list)) { let t = build(list); - heap.unsafeUnshare(t); + heap.unsafeUnshare(t) }; - heap; + heap }; -}; +} diff --git a/src/Int.mo b/src/Int.mo index f1f5c000..35c6fab4 100644 --- a/src/Int.mo +++ b/src/Int.mo @@ -18,7 +18,7 @@ module { /// Conversion. public let toText : Int -> Text = func(x) { if (x == 0) { - return "0"; + return "0" }; let isNegative = x < 0; @@ -41,23 +41,23 @@ module { case 7 { "7" }; case 8 { "8" }; case 9 { "9" }; - case _ { Prelude.unreachable() }; - }, + case _ { Prelude.unreachable() } + } ) # text; - int := int / base; + int := int / base }; - return if isNegative { "-" # text } else { text }; + return if isNegative { "-" # text } else { text } }; /// Returns the minimum of `x` and `y`. public func min(x : Int, y : Int) : Int { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Int, y : Int) : Int { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; // this is a local copy of deprecated Hash.hashNat8 (redefined to suppress the warning) @@ -66,12 +66,12 @@ module { for (natOfKey in key.vals()) { hash := hash +% natOfKey; hash := hash +% hash << 10; - hash := hash ^ (hash >> 6); + hash := hash ^ (hash >> 6) }; hash := hash +% hash << 3; hash := hash ^ (hash >> 11); hash := hash +% hash << 15; - return hash; + return hash }; /// Computes a hash from the least significant 32-bits of `i`, ignoring other bits. @@ -83,8 +83,8 @@ module { j & (255 << 0), j & (255 << 8), j & (255 << 16), - j & (255 << 24), - ]); + j & (255 << 24) + ]) }; /// @deprecated This function will be removed in future. @@ -96,8 +96,8 @@ module { j & (255 << 0), j & (255 << 8), j & (255 << 16), - j & (255 << 24), - ]); + j & (255 << 24) + ]) }; /// Returns `x == y`. @@ -120,7 +120,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Int, y : Int) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the negation of `x`, `-x` . @@ -146,4 +146,4 @@ module { /// Returns `x` to the power of `y`, `x ** y`. public func pow(x : Int, y : Int) : Int { x ** y }; -}; +} diff --git a/src/Int16.mo b/src/Int16.mo index b32de6c5..dfc8b176 100644 --- a/src/Int16.mo +++ b/src/Int16.mo @@ -26,22 +26,22 @@ module { /// Returns the Text representation of `x`. public func toText(x : Int16) : Text { - Int.toText(toInt(x)); + Int.toText(toInt(x)) }; /// Returns the absolute value of `x`. Traps when `x = -2^15`. public func abs(x : Int16) : Int16 { - fromInt(Int.abs(toInt(x))); + fromInt(Int.abs(toInt(x))) }; /// Returns the minimum of `x` and `y`. public func min(x : Int16, y : Int16) : Int16 { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Int16, y : Int16) : Int16 { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; /// Returns `x == y`. @@ -64,7 +64,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Int16, y : Int16) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the negation of `x`, `-x`. Traps on overflow. @@ -116,22 +116,22 @@ module { /// Returns the value of bit `p mod 16` in `x`, `(x & 2^(p mod 16)) == 2^(p mod 16)`. public func bittest(x : Int16, p : Nat) : Bool { - Prim.btstInt16(x, Prim.intToInt16(p)); + Prim.btstInt16(x, Prim.intToInt16(p)) }; /// Returns the value of setting bit `p mod 16` in `x` to `1`. public func bitset(x : Int16, p : Nat) : Int16 { - x | (1 << Prim.intToInt16(p)); + x | (1 << Prim.intToInt16(p)) }; /// Returns the value of clearing bit `p mod 16` in `x` to `0`. public func bitclear(x : Int16, p : Nat) : Int16 { - x & ^(1 << Prim.intToInt16(p)); + x & ^(1 << Prim.intToInt16(p)) }; /// Returns the value of flipping bit `p mod 16` in `x`. public func bitflip(x : Int16, p : Nat) : Int16 { - x ^ (1 << Prim.intToInt16(p)); + x ^ (1 << Prim.intToInt16(p)) }; /// Returns the count of non-zero bits in `x`. @@ -153,5 +153,5 @@ module { public func mulWrap(x : Int16, y : Int16) : Int16 { x *% y }; /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. Traps if `y < 0`. - public func powWrap(x : Int16, y : Int16) : Int16 { x **% y }; -}; + public func powWrap(x : Int16, y : Int16) : Int16 { x **% y } +} diff --git a/src/Int32.mo b/src/Int32.mo index d2aac647..7f5bd4f3 100644 --- a/src/Int32.mo +++ b/src/Int32.mo @@ -26,22 +26,22 @@ module { /// Returns the Text representation of `x`. public func toText(x : Int32) : Text { - Int.toText(toInt(x)); + Int.toText(toInt(x)) }; /// Returns the absolute value of `x`. Traps when `x = -2^31`. public func abs(x : Int32) : Int32 { - fromInt(Int.abs(toInt(x))); + fromInt(Int.abs(toInt(x))) }; /// Returns the minimum of `x` and `y`. public func min(x : Int32, y : Int32) : Int32 { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Int32, y : Int32) : Int32 { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; /// Returns `x == y`. @@ -64,7 +64,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Int32, y : Int32) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the negation of `x`, `-x`. Traps on overflow. @@ -116,22 +116,22 @@ module { /// Returns the value of bit `p mod 16` in `x`, `(x & 2^(p mod 16)) == 2^(p mod 16)`. public func bittest(x : Int32, p : Nat) : Bool { - Prim.btstInt32(x, Prim.intToInt32(p)); + Prim.btstInt32(x, Prim.intToInt32(p)) }; /// Returns the value of setting bit `p mod 16` in `x` to `1`. public func bitset(x : Int32, p : Nat) : Int32 { - x | (1 << Prim.intToInt32(p)); + x | (1 << Prim.intToInt32(p)) }; /// Returns the value of clearing bit `p mod 16` in `x` to `0`. public func bitclear(x : Int32, p : Nat) : Int32 { - x & ^(1 << Prim.intToInt32(p)); + x & ^(1 << Prim.intToInt32(p)) }; /// Returns the value of flipping bit `p mod 16` in `x`. public func bitflip(x : Int32, p : Nat) : Int32 { - x ^ (1 << Prim.intToInt32(p)); + x ^ (1 << Prim.intToInt32(p)) }; /// Returns the count of non-zero bits in `x`. @@ -155,4 +155,4 @@ module { /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. Traps if `y < 0`. public func powWrap(x : Int32, y : Int32) : Int32 { x **% y }; -}; +} diff --git a/src/Int64.mo b/src/Int64.mo index 89c3f719..d4739abe 100644 --- a/src/Int64.mo +++ b/src/Int64.mo @@ -26,22 +26,22 @@ module { /// Returns the Text representation of `x`. public func toText(x : Int64) : Text { - Int.toText(toInt(x)); + Int.toText(toInt(x)) }; /// Returns the absolute value of `x`. Traps when `x = -2^63`. public func abs(x : Int64) : Int64 { - fromInt(Int.abs(toInt(x))); + fromInt(Int.abs(toInt(x))) }; /// Returns the minimum of `x` and `y`. public func min(x : Int64, y : Int64) : Int64 { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Int64, y : Int64) : Int64 { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; /// Returns `x == y`. @@ -64,7 +64,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Int64, y : Int64) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the negation of `x`, `-x`. Traps on overflow. @@ -116,22 +116,22 @@ module { /// Returns the value of bit `p mod 64` in `x`, `(x & 2^(p mod 64)) == 2^(p mod 64)`. public func bittest(x : Int64, p : Nat) : Bool { - Prim.btstInt64(x, Prim.intToInt64(p)); + Prim.btstInt64(x, Prim.intToInt64(p)) }; /// Returns the value of setting bit `p mod 64` in `x` to `1`. public func bitset(x : Int64, p : Nat) : Int64 { - x | (1 << Prim.intToInt64(p)); + x | (1 << Prim.intToInt64(p)) }; /// Returns the value of clearing bit `p mod 64` in `x` to `0`. public func bitclear(x : Int64, p : Nat) : Int64 { - x & ^(1 << Prim.intToInt64(p)); + x & ^(1 << Prim.intToInt64(p)) }; /// Returns the value of flipping bit `p mod 64` in `x`. public func bitflip(x : Int64, p : Nat) : Int64 { - x ^ (1 << Prim.intToInt64(p)); + x ^ (1 << Prim.intToInt64(p)) }; /// Returns the count of non-zero bits in `x`. @@ -155,4 +155,4 @@ module { /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. Traps if `y < 0`. public func powWrap(x : Int64, y : Int64) : Int64 { x **% y }; -}; +} diff --git a/src/Int8.mo b/src/Int8.mo index d02a947c..a2e81f5b 100644 --- a/src/Int8.mo +++ b/src/Int8.mo @@ -26,22 +26,22 @@ module { /// Returns the Text representation of `x`. public func toText(x : Int8) : Text { - Int.toText(toInt(x)); + Int.toText(toInt(x)) }; /// Returns the absolute value of `x`. Traps when `x = -2^7`. public func abs(x : Int8) : Int8 { - fromInt(Int.abs(toInt(x))); + fromInt(Int.abs(toInt(x))) }; /// Returns the minimum of `x` and `y`. public func min(x : Int8, y : Int8) : Int8 { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Int8, y : Int8) : Int8 { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; /// Returns `x == y`. @@ -64,7 +64,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Int8, y : Int8) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the negation of `x`, `-x`. Traps on overflow. @@ -116,22 +116,22 @@ module { /// Returns the value of bit `p mod 8` in `x`, `(x & 2^(p mod 8)) == 2^(p mod 8)`. public func bittest(x : Int8, p : Nat) : Bool { - Prim.btstInt8(x, Prim.intToInt8(p)); + Prim.btstInt8(x, Prim.intToInt8(p)) }; /// Returns the value of setting bit `p mod 8` in `x` to `1`. public func bitset(x : Int8, p : Nat) : Int8 { - x | (1 << Prim.intToInt8(p)); + x | (1 << Prim.intToInt8(p)) }; /// Returns the value of clearing bit `p mod 8` in `x` to `0`. public func bitclear(x : Int8, p : Nat) : Int8 { - x & ^(1 << Prim.intToInt8(p)); + x & ^(1 << Prim.intToInt8(p)) }; /// Returns the value of flipping bit `p mod 8` in `x`. public func bitflip(x : Int8, p : Nat) : Int8 { - x ^ (1 << Prim.intToInt8(p)); + x ^ (1 << Prim.intToInt8(p)) }; /// Returns the count of non-zero bits in `x`. @@ -155,4 +155,4 @@ module { /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. Traps if `y < 0`. public func powWrap(x : Int8, y : Int8) : Int8 { x **% y }; -}; +} diff --git a/src/Iter.mo b/src/Iter.mo index ecc7969a..2d18c9b3 100644 --- a/src/Iter.mo +++ b/src/Iter.mo @@ -35,8 +35,8 @@ module { public class range(x : Nat, y : Int) { var i = x; public func next() : ?Nat { - if (i > y) { null } else { let j = i; i += 1; ?j }; - }; + if (i > y) { null } else { let j = i; i += 1; ?j } + } }; /// Like `range` but produces the values in the opposite @@ -44,8 +44,8 @@ module { public class revRange(x : Int, y : Int) { var i = x; public func next() : ?Int { - if (i < y) { null } else { let j = i; i -= 1; ?j }; - }; + if (i < y) { null } else { let j = i; i -= 1; ?j } + } }; /// Calls a function `f` on every value produced by an iterator and discards @@ -61,21 +61,21 @@ module { /// ``` public func iterate( xs : Iter, - f : (A, Nat) -> (), + f : (A, Nat) -> () ) { var i = 0; label l loop { switch (xs.next()) { case (?next) { - f(next, i); + f(next, i) }; case (null) { - break l; - }; + break l + } }; i += 1; - continue l; - }; + continue l + } }; /// Consumes an iterator and counts how many elements were produced @@ -83,7 +83,7 @@ module { public func size(xs : Iter) : Nat { var len = 0; iterate(xs, func(x, i) { len += 1 }); - len; + len }; /// Takes a function and an iterator and returns a new iterator that lazily applies @@ -101,13 +101,13 @@ module { public func next() : ?B { switch (xs.next()) { case (?next) { - ?f(next); + ?f(next) }; case (null) { - null; - }; - }; - }; + null + } + } + } }; /// Takes a function and an iterator and returns a new iterator that produces @@ -125,17 +125,17 @@ module { loop { switch (xs.next()) { case (null) { - return null; + return null }; case (?x) { if (f(x)) { - return ?x; - }; - }; - }; + return ?x + } + } + } }; - null; - }; + null + } }; /// Creates an iterator that produces an infinite sequence of `x`. @@ -149,8 +149,8 @@ module { /// ``` public func make(x : A) : Iter = object { public func next() : ?A { - ?x; - }; + ?x + } }; /// Creates an iterator that produces the elements of an Array in ascending index order. @@ -168,21 +168,21 @@ module { object { public func next() : ?A { if (ix >= size) { - return null; + return null } else { let res = ?(xs[ix]); ix += 1; - return res; - }; - }; - }; + return res + } + } + } }; /// Like `fromArray` but for Arrays with mutable elements. Captures /// the elements of the Array at the time the iterator is created, so /// further modifications won't be reflected in the iterator. public func fromArrayMut(xs : [var A]) : Iter { - fromArray(Array.freeze(xs)); + fromArray(Array.freeze(xs)) }; /// Like `fromArray` but for Lists. @@ -197,12 +197,12 @@ module { public func toArray(xs : Iter) : [A] { let buffer = Buffer.Buffer(8); iterate(xs, func(x : A, ix : Nat) { buffer.add(x) }); - return Buffer.toArray(buffer); + return Buffer.toArray(buffer) }; /// Like `toArray` but for Arrays with mutable elements. public func toArrayMut(xs : Iter) : [var A] { - Array.thaw(toArray(xs)); + Array.thaw(toArray(xs)) }; /// Like `toArray` but for Lists. @@ -211,17 +211,17 @@ module { iterate( xs, func(x, _i) { - result := List.push(x, result); - }, + result := List.push(x, result) + } ); - List.reverse(result); + List.reverse(result) }; /// Sorted iterator. Will iterate over *all* elements to sort them, necessarily. public func sort(xs : Iter, compare : (A, A) -> Order.Order) : Iter { let a = toArrayMut(xs); Array.sortInPlace(a, compare); - fromArrayMut(a); + fromArrayMut(a) }; -}; +} diff --git a/src/IterType.mo b/src/IterType.mo index 238ee399..1c258ff4 100644 --- a/src/IterType.mo +++ b/src/IterType.mo @@ -3,5 +3,5 @@ // Just here to break cyclic module definitions module { - public type Iter = { next : () -> ?T }; -}; + public type Iter = { next : () -> ?T } +} diff --git a/src/List.mo b/src/List.mo index a6cf56a5..9323e3f4 100644 --- a/src/List.mo +++ b/src/List.mo @@ -20,8 +20,8 @@ module { public func isNil(l : List) : Bool { switch l { case null { true }; - case _ { false }; - }; + case _ { false } + } }; /// Construct a list by pre-pending a value. @@ -33,8 +33,8 @@ module { switch l { case null { null }; case (?(x, null)) { ?x }; - case (?(_, t)) { last(t) }; - }; + case (?(_, t)) { last(t) } + } }; /// Treat the list as a stack. @@ -42,8 +42,8 @@ module { public func pop(l : List) : (?T, List) { switch l { case null { (null, null) }; - case (?(h, t)) { (?h, t) }; - }; + case (?(h, t)) { (?h, t) } + } }; /// Return the length of the list. @@ -51,10 +51,10 @@ module { func rec(l : List, n : Nat) : Nat { switch l { case null { n }; - case (?(_, t)) { rec(t, n + 1) }; - }; + case (?(_, t)) { rec(t, n + 1) } + } }; - rec(l, 0); + rec(l, 0) }; /// Access any item in a list, zero-based. /// @@ -65,8 +65,8 @@ module { switch (n, l) { case (_, null) { null }; case (0, (?(h, t))) { ?h }; - case (_, (?(_, t))) { get(t, n - 1) }; - }; + case (_, (?(_, t))) { get(t, n - 1) } + } }; /// Reverses the list @@ -74,10 +74,10 @@ module { func rec(l : List, r : List) : List { switch l { case null { r }; - case (?(h, t)) { rec(t, ?(h, r)) }; - }; + case (?(h, t)) { rec(t, ?(h, r)) } + } }; - rec(l, null); + rec(l, null) }; /// Call the given function with each list element in turn. @@ -87,8 +87,8 @@ module { public func iterate(l : List, f : T -> ()) { switch l { case null { () }; - case (?(h, t)) { f(h); iterate(t, f) }; - }; + case (?(h, t)) { f(h); iterate(t, f) } + } }; /// Call the given function on each list element and collect the results @@ -96,8 +96,8 @@ module { public func map(l : List, f : T -> S) : List { switch l { case null { null }; - case (?(h, t)) { ?(f(h), map(t, f)) }; - }; + case (?(h, t)) { ?(f(h), map(t, f)) } + } }; /// Create a new list with only those elements of the original list for which @@ -107,12 +107,12 @@ module { case null { null }; case (?(h, t)) { if (f(h)) { - ?(h, filter(t, f)); + ?(h, filter(t, f)) } else { - filter(t, f); - }; - }; - }; + filter(t, f) + } + } + } }; /// Create two new lists from the results of a given function (`f`). @@ -126,13 +126,13 @@ module { if (f(h)) { // call f in-order let (l, r) = partition(t, f); - (?(h, l), r); + (?(h, l), r) } else { let (l, r) = partition(t, f); - (l, ?(h, r)); - }; - }; - }; + (l, ?(h, r)) + } + } + } }; /// Call the given function on each list element, and collect the non-null results @@ -143,10 +143,10 @@ module { case (?(h, t)) { switch (f(h)) { case null { mapFilter(t, f) }; - case (?h_) { ?(h_, mapFilter(t, f)) }; - }; - }; - }; + case (?h_) { ?(h_, mapFilter(t, f)) } + } + } + } }; /// Maps a Result-returning function over a List and returns either @@ -158,32 +158,32 @@ module { case (?(head, tail)) { switch (f(head)) { case (#err(err)) { #err(err) }; - case (#ok(ok)) { go(tail, ?(ok, acc)) }; - }; - }; - }; + case (#ok(ok)) { go(tail, ?(ok, acc)) } + } + } + } }; - Result.mapOk(go(xs, null), func(xs : List) : List = reverse(xs)); + Result.mapOk(go(xs, null), func(xs : List) : List = reverse(xs)) }; /// Append the elements from the reverse of one list to another list. func revAppend(l : List, m : List) : List { switch l { case null { m }; - case (?(h, t)) { revAppend(t, ?(h, m)) }; - }; + case (?(h, t)) { revAppend(t, ?(h, m)) } + } }; /// Append the elements from one list to another list. public func append(l : List, m : List) : List { - revAppend(reverse(l), m); + revAppend(reverse(l), m) }; /// Concatenate a list of lists. /// /// In some languages, this operation is also known as a `list join`. public func flatten(l : List>) : List { - foldLeft, List>(l, null, func(a, b) { append(a, b) }); + foldLeft, List>(l, null, func(a, b) { append(a, b) }) }; /// Returns the first `n` elements of the given list. @@ -193,8 +193,8 @@ module { switch (l, n) { case (_, 0) { null }; case (null, _) { null }; - case (?(h, t), m) { ?(h, take(t, m - 1)) }; - }; + case (?(h, t), m) { ?(h, take(t, m - 1)) } + } }; /// Drop the first `n` elements from the given list. @@ -202,24 +202,24 @@ module { switch (l, n) { case (l_, 0) { l_ }; case (null, _) { null }; - case ((?(h, t)), m) { drop(t, m - 1) }; - }; + case ((?(h, t)), m) { drop(t, m - 1) } + } }; /// Fold the list left-to-right using the given function (`f`). public func foldLeft(l : List, a : S, f : (S, T) -> S) : S { switch l { case null { a }; - case (?(h, t)) { foldLeft(t, f(a, h), f) }; - }; + case (?(h, t)) { foldLeft(t, f(a, h), f) } + } }; /// Fold the list right-to-left using the given function (`f`). public func foldRight(l : List, a : S, f : (T, S) -> S) : S { switch l { case null { a }; - case (?(h, t)) { f(h, foldRight(t, a, f)) }; - }; + case (?(h, t)) { f(h, foldRight(t, a, f)) } + } }; /// Return the first element for which the given predicate `f` is true, @@ -227,8 +227,8 @@ module { public func find(l : List, f : T -> Bool) : ?T { switch l { case null { null }; - case (?(h, t)) { if (f(h)) { ?h } else { find(t, f) } }; - }; + case (?(h, t)) { if (f(h)) { ?h } else { find(t, f) } } + } }; /// Return true if there exists a list element for which @@ -236,8 +236,8 @@ module { public func some(l : List, f : T -> Bool) : Bool { switch l { case null { false }; - case (?(h, t)) { f(h) or some(t, f) }; - }; + case (?(h, t)) { f(h) or some(t, f) } + } }; /// Return true if the given predicate `f` is true for all list @@ -245,8 +245,8 @@ module { public func all(l : List, f : T -> Bool) : Bool { switch l { case null { true }; - case (?(h, t)) { f(h) and all(t, f) }; - }; + case (?(h, t)) { f(h) and all(t, f) } + } }; /// Merge two ordered lists into a single ordered list. @@ -258,12 +258,12 @@ module { case (_, null) { l1 }; case (?(h1, t1), ?(h2, t2)) { if (lte(h1, h2)) { - ?(h1, merge(t1, l2, lte)); + ?(h1, merge(t1, l2, lte)) } else { - ?(h2, merge(l1, t2, lte)); - }; - }; - }; + ?(h2, merge(l1, t2, lte)) + } + } + } }; /// Compare two lists using lexicographic ordering specified by the given relation `lte`. @@ -275,12 +275,12 @@ module { case (?(h1, t1), ?(h2, t2)) { let hOrder = compElm(h1, h2); if (Order.isEqual(hOrder)) { - compare(t1, t2, compElm); + compare(t1, t2, compElm) } else { - hOrder; - }; - }; - }; + hOrder + } + } + } }; /// Compare two lists for equality as specified by the given relation `eq` on the elements. @@ -292,8 +292,8 @@ module { case (null, null) { true }; case (null, _) { false }; case (_, null) { false }; - case (?(h1, t1), ?(h2, t2)) { eq(h1, h2) and equal(t1, t2, eq) }; - }; + case (?(h1, t1), ?(h2, t2)) { eq(h1, h2) and equal(t1, t2, eq) } + } }; /// Generate a list based on a length and a function that maps from @@ -303,9 +303,9 @@ module { var l : List = null; while (i < n) { l := ?(f(i), l); - i += 1; + i += 1 }; - reverse(l); + reverse(l) }; /// Create a list with exactly one element. @@ -317,9 +317,9 @@ module { var l : List = null; while (i < n) { l := ?(x, l); - i += 1; + i += 1 }; - l; + l }; /// Create a list of pairs from a pair of lists. @@ -336,7 +336,7 @@ module { public func zipWith( xs : List, ys : List, - f : (X, Y) -> Z, + f : (X, Y) -> Z ) : List { switch (pop(xs)) { case (null, _) { null }; @@ -344,11 +344,11 @@ module { switch (pop(ys)) { case (null, _) { null }; case (?y, yt) { - push(f(x, y), zipWith(xt, yt, f)); - }; - }; - }; - }; + push(f(x, y), zipWith(xt, yt, f)) + } + } + } + } }; /// Split the given list at the given zero-based index. @@ -360,13 +360,13 @@ module { case (?h, t) { if (n == 1) { (make(h), t) } else { let (l, r) = rec(n - 1, t); - (push(h, l), r); - }; - }; - }; + (push(h, l), r) + } + } + } }; - rec(n, xs); - }; + rec(n, xs) + } }; /// Split the given list into chunks of length `n`. @@ -375,10 +375,10 @@ module { public func chunks(n : Nat, xs : List) : List> { let (l, r) = split(n, xs); if (isNil(l)) { - null; + null } else { - push>(l, chunks(n, r)); - }; + push>(l, chunks(n, r)) + } }; /// Convert an array into a list. @@ -387,9 +387,9 @@ module { xs, nil(), func(x : A, ys : List) : List { - push(x, ys); - }, - ); + push(x, ys) + } + ) }; /// Convert a mutable array into a list. @@ -406,10 +406,10 @@ module { list := popped.1; switch (popped.0) { case null { loop { assert false } }; - case (?x) x; - }; - }, - ); + case (?x) x + } + } + ) }; /// Create a mutable array from a list. @@ -421,9 +421,9 @@ module { object { public func next() : ?A = switch state { case (?(hd, tl)) { state := tl; ?hd }; - case _ null; - }; - }; + case _ null + } + } } -}; +} diff --git a/src/Nat.mo b/src/Nat.mo index dc11aea0..8b0b9ded 100644 --- a/src/Nat.mo +++ b/src/Nat.mo @@ -17,12 +17,12 @@ module { /// Returns the minimum of `x` and `y`. public func min(x : Nat, y : Nat) : Nat { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Nat, y : Nat) : Nat { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; /// Returns `x == y`. @@ -45,7 +45,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Nat, y : Nat) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the sum of `x` and `y`, `x + y`. @@ -69,4 +69,4 @@ module { /// Returns `x` to the power of `y`, `x ** y`. public func pow(x : Nat, y : Nat) : Nat { x ** y }; -}; +} diff --git a/src/Nat16.mo b/src/Nat16.mo index d7820132..7af8b62d 100644 --- a/src/Nat16.mo +++ b/src/Nat16.mo @@ -20,17 +20,17 @@ module { /// Returns the Text representation of `x`. public func toText(x : Nat16) : Text { - Nat.toText(toNat(x)); + Nat.toText(toNat(x)) }; /// Returns the minimum of `x` and `y`. public func min(x : Nat16, y : Nat16) : Nat16 { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Nat16, y : Nat16) : Nat16 { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; /// Returns `x == y`. @@ -53,7 +53,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Nat16, y : Nat16) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the sum of `x` and `y`, `x + y`. Traps on overflow. @@ -102,22 +102,22 @@ module { /// Returns the value of bit `p mod 16` in `x`, `(x & 2^(p mod 16)) == 2^(p mod 16)`. public func bittest(x : Nat16, p : Nat) : Bool { - Prim.btstNat16(x, Prim.natToNat16(p)); + Prim.btstNat16(x, Prim.natToNat16(p)) }; /// Returns the value of setting bit `p mod 16` in `x` to `1`. public func bitset(x : Nat16, p : Nat) : Nat16 { - x | (1 << Prim.natToNat16(p)); + x | (1 << Prim.natToNat16(p)) }; /// Returns the value of clearing bit `p mod 16` in `x` to `0`. public func bitclear(x : Nat16, p : Nat) : Nat16 { - x & ^(1 << Prim.natToNat16(p)); + x & ^(1 << Prim.natToNat16(p)) }; /// Returns the value of flipping bit `p mod 16` in `x`. public func bitflip(x : Nat16, p : Nat) : Nat16 { - x ^ (1 << Prim.natToNat16(p)); + x ^ (1 << Prim.natToNat16(p)) }; /// Returns the count of non-zero bits in `x`. @@ -141,4 +141,4 @@ module { /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. public func powWrap(x : Nat16, y : Nat16) : Nat16 { x **% y }; -}; +} diff --git a/src/Nat32.mo b/src/Nat32.mo index 3d0ce44f..026ee875 100644 --- a/src/Nat32.mo +++ b/src/Nat32.mo @@ -20,17 +20,17 @@ module { /// Returns the Text representation of `x`. public func toText(x : Nat32) : Text { - Nat.toText(toNat(x)); + Nat.toText(toNat(x)) }; /// Returns the minimum of `x` and `y`. public func min(x : Nat32, y : Nat32) : Nat32 { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Nat32, y : Nat32) : Nat32 { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; /// Returns `x == y`. @@ -53,7 +53,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Nat32, y : Nat32) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the sum of `x` and `y`, `x + y`. Traps on overflow. @@ -102,22 +102,22 @@ module { /// Returns the value of bit `p mod 32` in `x`, `(x & 2^(p mod 32)) == 2^(p mod 32)`. public func bittest(x : Nat32, p : Nat) : Bool { - Prim.btstNat32(x, Prim.natToNat32(p)); + Prim.btstNat32(x, Prim.natToNat32(p)) }; /// Returns the value of setting bit `p mod 32` in `x` to `1`. public func bitset(x : Nat32, p : Nat) : Nat32 { - x | (1 << Prim.natToNat32(p)); + x | (1 << Prim.natToNat32(p)) }; /// Returns the value of clearing bit `p mod 32` in `x` to `0`. public func bitclear(x : Nat32, p : Nat) : Nat32 { - x & ^(1 << Prim.natToNat32(p)); + x & ^(1 << Prim.natToNat32(p)) }; /// Returns the value of flipping bit `p mod 32` in `x`. public func bitflip(x : Nat32, p : Nat) : Nat32 { - x ^ (1 << Prim.natToNat32(p)); + x ^ (1 << Prim.natToNat32(p)) }; /// Returns the count of non-zero bits in `x`. @@ -141,4 +141,4 @@ module { /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. public func powWrap(x : Nat32, y : Nat32) : Nat32 { x **% y }; -}; +} diff --git a/src/Nat64.mo b/src/Nat64.mo index 14fc0b77..c3e7f209 100644 --- a/src/Nat64.mo +++ b/src/Nat64.mo @@ -20,17 +20,17 @@ module { /// Returns the Text representation of `x`. public func toText(x : Nat64) : Text { - Nat.toText(toNat(x)); + Nat.toText(toNat(x)) }; /// Returns the minimum of `x` and `y`. public func min(x : Nat64, y : Nat64) : Nat64 { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Nat64, y : Nat64) : Nat64 { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; /// Returns `x == y`. @@ -53,7 +53,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Nat64, y : Nat64) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the sum of `x` and `y`, `x + y`. Traps on overflow. @@ -102,22 +102,22 @@ module { /// Returns the value of bit `p mod 64` in `x`, `(x & 2^(p mod 64)) == 2^(p mod 64)`. public func bittest(x : Nat64, p : Nat) : Bool { - Prim.btstNat64(x, Prim.natToNat64(p)); + Prim.btstNat64(x, Prim.natToNat64(p)) }; /// Returns the value of setting bit `p mod 64` in `x` to `1`. public func bitset(x : Nat64, p : Nat) : Nat64 { - x | (1 << Prim.natToNat64(p)); + x | (1 << Prim.natToNat64(p)) }; /// Returns the value of clearing bit `p mod 64` in `x` to `0`. public func bitclear(x : Nat64, p : Nat) : Nat64 { - x & ^(1 << Prim.natToNat64(p)); + x & ^(1 << Prim.natToNat64(p)) }; /// Returns the value of flipping bit `p mod 64` in `x`. public func bitflip(x : Nat64, p : Nat) : Nat64 { - x ^ (1 << Prim.natToNat64(p)); + x ^ (1 << Prim.natToNat64(p)) }; /// Returns the count of non-zero bits in `x`. @@ -141,4 +141,4 @@ module { /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. public func powWrap(x : Nat64, y : Nat64) : Nat64 { x **% y }; -}; +} diff --git a/src/Nat8.mo b/src/Nat8.mo index cdf29fdf..4fffd38e 100644 --- a/src/Nat8.mo +++ b/src/Nat8.mo @@ -20,17 +20,17 @@ module { /// Returns the Text representation of `x`. public func toText(x : Nat8) : Text { - Nat.toText(toNat(x)); + Nat.toText(toNat(x)) }; /// Returns the minimum of `x` and `y`. public func min(x : Nat8, y : Nat8) : Nat8 { - if (x < y) { x } else { y }; + if (x < y) { x } else { y } }; /// Returns the maximum of `x` and `y`. public func max(x : Nat8, y : Nat8) : Nat8 { - if (x < y) { y } else { x }; + if (x < y) { y } else { x } }; /// Returns `x == y`. @@ -53,7 +53,7 @@ module { /// Returns the order of `x` and `y`. public func compare(x : Nat8, y : Nat8) : { #less; #equal; #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } }; /// Returns the sum of `x` and `y`, `x + y`. Traps on overflow. @@ -102,22 +102,22 @@ module { /// Returns the value of bit `p mod 8` in `x`, `(x & 2^(p mod 8)) == 2^(p mod 8)`. public func bittest(x : Nat8, p : Nat) : Bool { - Prim.btstNat8(x, Prim.natToNat8(p)); + Prim.btstNat8(x, Prim.natToNat8(p)) }; /// Returns the value of setting bit `p mod 8` in `x` to `1`. public func bitset(x : Nat8, p : Nat) : Nat8 { - x | (1 << Prim.natToNat8(p)); + x | (1 << Prim.natToNat8(p)) }; /// Returns the value of clearing bit `p mod 8` in `x` to `0`. public func bitclear(x : Nat8, p : Nat) : Nat8 { - x & ^(1 << Prim.natToNat8(p)); + x & ^(1 << Prim.natToNat8(p)) }; /// Returns the value of flipping bit `p mod 8` in `x`. public func bitflip(x : Nat8, p : Nat) : Nat8 { - x ^ (1 << Prim.natToNat8(p)); + x ^ (1 << Prim.natToNat8(p)) }; /// Returns the count of non-zero bits in `x`. @@ -141,4 +141,4 @@ module { /// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. public func powWrap(x : Nat8, y : Nat8) : Nat8 { x **% y }; -}; +} diff --git a/src/None.mo b/src/None.mo index e3fe17b9..b3eaafcc 100644 --- a/src/None.mo +++ b/src/None.mo @@ -14,6 +14,6 @@ module { /// Turns an absurd value into an arbitrary type. public let impossible : None -> A = func(x : None) : A { - switch (x) {}; - }; -}; + switch (x) {} + } +} diff --git a/src/Option.mo b/src/Option.mo index 70597bb3..31ded976 100644 --- a/src/Option.mo +++ b/src/Option.mo @@ -32,14 +32,14 @@ module { /// `get(null, d) = d`. public func get(x : ?T, default : T) : T = switch x { case null { default }; - case (?x_) { x_ }; + case (?x_) { x_ } }; /// Unwraps an optional value using a function, or returns the default, i.e. /// `option(?x, f, d) = f x` and `option(null, f, d) = d`. public func getMapped(x : ?A, f : A -> B, default : B) : B = switch x { case null { default }; - case (?x_) { f(x_) }; + case (?x_) { f(x_) } }; /// Applies a function to the wrapped value. `null`'s are left untouched. @@ -50,7 +50,7 @@ module { /// ``` public func map(x : ?A, f : A -> B) : ?B = switch x { case null { null }; - case (?x_) { ?f(x_) }; + case (?x_) { ?f(x_) } }; /// Applies a function to the wrapped value, but discards the result. Use @@ -66,7 +66,7 @@ module { /// ``` public func iterate(x : ?A, f : A -> ()) = switch x { case null {}; - case (?x_) { f(x_) }; + case (?x_) { f(x_) } }; /// Applies an optional function to an optional value. Returns `null` if at @@ -74,12 +74,12 @@ module { public func apply(x : ?A, f : ?(A -> B)) : ?B { switch (f, x) { case (?f_, ?x_) { - ?f_(x_); + ?f_(x_) }; case (_, _) { - null; - }; - }; + null + } + } }; /// Applies a function to an optional value. Returns `null` if the argument is @@ -87,12 +87,12 @@ module { public func chain(x : ?A, f : A -> ?B) : ?B { switch (x) { case (?x_) { - f(x_); + f(x_) }; case (null) { - null; - }; - }; + null + } + } }; /// Given an optional optional value, removes one layer of optionality. @@ -106,9 +106,9 @@ module { chain( x, func(x_ : ?A) : ?A { - x_; - }, - ); + x_ + } + ) }; /// Creates an optional value from a definite value. @@ -121,27 +121,27 @@ module { /// Returns true if the argument is not `null`, otherwise returns false. public func isSome(x : ?Any) : Bool = switch x { case null { false }; - case _ { true }; + case _ { true } }; /// Returns true if the argument is `null`, otherwise returns false. public func isNull(x : ?Any) : Bool = switch x { case null { true }; - case _ { false }; + case _ { false } }; /// Asserts that the value is not `null`; fails otherwise. /// @deprecated Option.assertSome will be removed soon; use an assert expression instead public func assertSome(x : ?Any) = switch x { case null { P.unreachable() }; - case _ {}; + case _ {} }; /// Asserts that the value _is_ `null`; fails otherwise. /// @deprecated Option.assertNull will be removed soon; use an assert expression instead public func assertNull(x : ?Any) = switch x { case null {}; - case _ { P.unreachable() }; + case _ { P.unreachable() } }; /// Unwraps an optional value, i.e. `unwrap(?x) = x`. @@ -149,6 +149,6 @@ module { /// @deprecated Option.unwrap is unsafe and fails if the argument is null; it will be removed soon; use a `switch` or `do?` expression instead public func unwrap(x : ?T) : T = switch x { case null { P.unreachable() }; - case (?x_) { x_ }; - }; -}; + case (?x_) { x_ } + } +} diff --git a/src/Order.mo b/src/Order.mo index dd9469a2..da271ed8 100644 --- a/src/Order.mo +++ b/src/Order.mo @@ -6,31 +6,31 @@ module { public type Order = { #less; #equal; - #greater; + #greater }; /// Check if an order is #less. public func isLess(order : Order) : Bool { switch order { case (#less) { true }; - case _ { false }; - }; + case _ { false } + } }; /// Check if an order is #equal. public func isEqual(order : Order) : Bool { switch order { case (#equal) { true }; - case _ { false }; - }; + case _ { false } + } }; /// Check if an order is #greater. public func isGreater(order : Order) : Bool { switch order { case (#greater) { true }; - case _ { false }; - }; + case _ { false } + } }; /// Returns true if only if `o1` and `o2` are the same ordering. @@ -39,8 +39,8 @@ module { case (#less, #less) { true }; case (#equal, #equal) { true }; case (#greater, #greater) { true }; - case _ { false }; - }; + case _ { false } + } }; -}; +} diff --git a/src/Prelude.mo b/src/Prelude.mo index a285088d..f16f35d6 100644 --- a/src/Prelude.mo +++ b/src/Prelude.mo @@ -15,11 +15,11 @@ module { /// Each have calls are well-typed in all typing contexts, which /// trap in all execution contexts. public func nyi() : None { - Debug.trap("Prelude.nyi()"); + Debug.trap("Prelude.nyi()") }; public func xxx() : None { - Debug.trap("Prelude.xxx()"); + Debug.trap("Prelude.xxx()") }; /// Mark unreachable code with the `unreachable` function. @@ -27,7 +27,7 @@ module { /// Calls are well-typed in all typing contexts, and they /// trap in all execution contexts. public func unreachable() : None { - Debug.trap("Prelude.unreachable()"); + Debug.trap("Prelude.unreachable()") }; -}; +} diff --git a/src/Principal.mo b/src/Principal.mo index 5843f8fe..2799b005 100644 --- a/src/Principal.mo +++ b/src/Principal.mo @@ -51,8 +51,8 @@ module { public func compare(x : Principal, y : Principal) : { #less; #equal; - #greater; + #greater } { - if (x < y) { #less } else if (x == y) { #equal } else { #greater }; - }; -}; + if (x < y) { #less } else if (x == y) { #equal } else { #greater } + } +} diff --git a/src/RBTree.mo b/src/RBTree.mo index 6f692aec..cbf29a4e 100644 --- a/src/RBTree.mo +++ b/src/RBTree.mo @@ -14,7 +14,7 @@ module { /// Ordered, (red-black) tree of entries. public type Tree = { #node : (Color, Tree, (X, ?Y), Tree); - #leaf; + #leaf }; /// Create an order map from an order function for its keys. @@ -28,38 +28,38 @@ module { /// for drawing, pretty-printing and non-OO contexts /// (e.g., async args and results): public func share() : Tree { - tree; + tree }; /// Get the value associated with a given key. public func get(x : X) : ?Y { - getRec(x, compareTo, tree); + getRec(x, compareTo, tree) }; /// Replace the value associated with a given key. public func replace(x : X, y : Y) : ?Y { let (res, t) = insertRoot(x, compareTo, y, tree); tree := t; - res; + res }; /// Put an entry: A value associated with a given key. public func put(x : X, y : Y) { let (res, t) = insertRoot(x, compareTo, y, tree); - tree := t; + tree := t }; /// Delete the entry associated with a given key. public func delete(x : X) { let (res, t) = removeRec(x, compareTo, tree); - tree := t; + tree := t }; /// Remove the entry associated with a given key. public func remove(x : X) : ?Y { let (res, t) = removeRec(x, compareTo, tree); tree := t; - res; + res }; /// An iterator for the key-value entries of the map, in ascending key order. @@ -85,26 +85,26 @@ module { case (_, null) { null }; case (_, ?(#tr(#leaf), ts)) { trees := ts; - next(); + next() }; case (_, ?(#xy(xy), ts)) { trees := ts; switch (xy.1) { case null { next() }; - case (?y) { ?(xy.0, y) }; - }; + case (?y) { ?(xy.0, y) } + } }; case (#fwd, ?(#tr(#node(_, l, xy, r)), ts)) { trees := ?(#tr(l), ?(#xy(xy), ?(#tr(r), ts))); - next(); + next() }; case (#bwd, ?(#tr(#node(_, l, xy, r)), ts)) { trees := ?(#tr(r), ?(#xy(xy), ?(#tr(l), ts))); - next(); - }; - }; - }; - }; + next() + } + } + } + } }; /// Remove the value associated with a given key. @@ -115,16 +115,16 @@ module { switch (compareTo(x, xy.0)) { case (#less) { let (yo, l2) = removeRec(x, compareTo, l); - (yo, #node(c, l2, xy, r)); + (yo, #node(c, l2, xy, r)) }; case (#equal) { (xy.1, #node(c, l, (x, null), r)) }; case (#greater) { let (yo, r2) = removeRec(x, compareTo, r); - (yo, #node(c, l, xy, r2)); - }; - }; - }; - }; + (yo, #node(c, l, xy, r2)) + } + } + } + } }; func bal(color : Color, lt : Tree, kv : (X, ?Y), rt : Tree) : Tree { @@ -132,26 +132,26 @@ module { // following notes from [Ravi Chugh](https://www.classes.cs.uchicago.edu/archive/2019/spring/22300-1/lectures/RedBlackTrees/index.html) switch (color, lt, kv, rt) { case (#B, #node(#R, #node(#R, a, x, b), y, c), z, d) { - #node(#R, #node(#B, a, x, b), y, #node(#B, c, z, d)); + #node(#R, #node(#B, a, x, b), y, #node(#B, c, z, d)) }; case (#B, #node(#R, a, x, #node(#R, b, y, c)), z, d) { - #node(#R, #node(#B, a, x, b), y, #node(#B, c, z, d)); + #node(#R, #node(#B, a, x, b), y, #node(#B, c, z, d)) }; case (#B, a, x, #node(#R, #node(#R, b, y, c), z, d)) { - #node(#R, #node(#B, a, x, b), y, #node(#B, c, z, d)); + #node(#R, #node(#B, a, x, b), y, #node(#B, c, z, d)) }; case (#B, a, x, #node(#R, b, y, #node(#R, c, z, d))) { - #node(#R, #node(#B, a, x, b), y, #node(#B, c, z, d)); + #node(#R, #node(#B, a, x, b), y, #node(#B, c, z, d)) }; - case _ { #node(color, lt, kv, rt) }; - }; + case _ { #node(color, lt, kv, rt) } + } }; func insertRoot(x : X, compareTo : (X, X) -> O.Order, y : Y, t : Tree) : (?Y, Tree) { switch (insertRec(x, compareTo, y, t)) { case (_, #leaf) { assert false; loop {} }; - case (yo, #node(_, l, xy, r)) { (yo, #node(#B, l, xy, r)) }; - }; + case (yo, #node(_, l, xy, r)) { (yo, #node(#B, l, xy, r)) } + } }; func insertRec(x : X, compareTo : (X, X) -> O.Order, y : Y, t : Tree) : (?Y, Tree) { @@ -161,16 +161,16 @@ module { switch (compareTo(x, xy.0)) { case (#less) { let (yo, l2) = insertRec(x, compareTo, y, l); - (yo, bal(c, l2, xy, r)); + (yo, bal(c, l2, xy, r)) }; case (#equal) { (xy.1, #node(c, l, (x, ?y), r)) }; case (#greater) { let (yo, r2) = insertRec(x, compareTo, y, r); - (yo, bal(c, l, xy, r2)); - }; - }; - }; - }; + (yo, bal(c, l, xy, r2)) + } + } + } + } }; func getRec(x : X, compareTo : (X, X) -> O.Order, t : Tree) : ?Y { @@ -180,19 +180,19 @@ module { switch (compareTo(x, xy.0)) { case (#less) { getRec(x, compareTo, l) }; case (#equal) { xy.1 }; - case (#greater) { getRec(x, compareTo, r) }; - }; - }; - }; + case (#greater) { getRec(x, compareTo, r) } + } + } + } }; func height(t : Tree) : Nat { switch t { case (#leaf) { 0 }; case (#node(_, l, _, r)) { - Nat.max(height(l), height(r)) + 1; - }; - }; + Nat.max(height(l), height(r)) + 1 + } + } }; /// The size of the tree as the number of key-value entries. @@ -200,9 +200,9 @@ module { switch t { case (#leaf) { 0 }; case (#node(_, l, xy, r)) { - size(l) + size(r) + (switch (xy.1) { case null 0; case _ 1 }); - }; - }; + size(l) + size(r) + (switch (xy.1) { case null 0; case _ 1 }) + } + } }; -}; +} diff --git a/src/Random.mo b/src/Random.mo index 13ee8601..a484a80f 100644 --- a/src/Random.mo +++ b/src/Random.mo @@ -40,7 +40,7 @@ module { /// Uniformly distributes outcomes in the numeric range [0 .. 255]. /// Consumes 1 byte of entropy. public func byte() : ?Nat8 { - it.next(); + it.next() }; /// Bool iterator splitting up a byte of entropy into 8 bits @@ -54,21 +54,21 @@ module { case (?w) { byte := w; mask := 0x40; - ?(0 : Nat8 != byte & (0x80 : Nat8)); - }; - }; + ?(0 : Nat8 != byte & (0x80 : Nat8)) + } + } } else { let m = mask; mask >>= (1 : Nat8); - ?(0 : Nat8 != byte & m); - }; - }; + ?(0 : Nat8 != byte & m) + } + } }; /// Simulates a coin toss. Both outcomes have equal probability. /// Consumes 1 bit of entropy (amortised). public func coin() : ?Bool { - bit.next(); + bit.next() }; /// Uniformly distributes outcomes in the numeric range [0 .. 2^p - 1]. @@ -78,15 +78,15 @@ module { var acc : Nat = 0; for (i in it) { if (8 : Nat8 <= pp) { acc := acc * 256 + Prim.nat8ToNat(i) } else if (0 : Nat8 == pp) { - return ?acc; + return ?acc } else { acc *= Prim.nat8ToNat(1 << pp); let mask : Nat8 = 0xff >> (8 - pp); - return ?(acc + Prim.nat8ToNat(i & mask)); + return ?(acc + Prim.nat8ToNat(i & mask)) }; - pp -= 8; + pp -= 8 }; - null; + null }; /// Counts the number of heads in `n` fair coin tosses. @@ -96,16 +96,16 @@ module { var acc : Nat8 = 0; for (i in it) { if (8 : Nat8 <= nn) { acc +%= Prim.popcntNat8(i) } else if (0 : Nat8 == nn) { - return ?acc; + return ?acc } else { let mask : Nat8 = 0xff << (8 - nn); let residue = Prim.popcntNat8(i & mask); - return ?(acc +% residue); + return ?(acc +% residue) }; - nn -= 8; + nn -= 8 }; - null; - }; + null + } }; let raw_rand = (actor "aaaaa-aa" : actor { raw_rand : () -> async Blob }).raw_rand; @@ -115,8 +115,8 @@ module { public func byteFrom(seed : Blob) : Nat8 { switch (seed.vals().next()) { case (?w) { w }; - case _ { P.unreachable() }; - }; + case _ { P.unreachable() } + } }; /// Simulates a coin toss. @@ -124,8 +124,8 @@ module { public func coinFrom(seed : Blob) : Bool { switch (seed.vals().next()) { case (?w) { w > (127 : Nat8) }; - case _ { P.unreachable() }; - }; + case _ { P.unreachable() } + } }; /// Obtains a full blob (32 bytes) worth of fresh entropy. @@ -134,7 +134,7 @@ module { /// Distributes outcomes in the numeric range [0 .. 2^p - 1]. /// Seed blob must contain at least ((p+7) / 8) bytes. public func rangeFrom(p : Nat8, seed : Blob) : Nat { - rangeIter(p, seed.vals()); + rangeIter(p, seed.vals()) }; // internal worker method, expects iterator with sufficient supply @@ -143,21 +143,21 @@ module { var acc : Nat = 0; for (i in it) { if (8 : Nat8 <= pp) { acc := acc * 256 + Prim.nat8ToNat(i) } else if (0 : Nat8 == pp) { - return acc; + return acc } else { acc *= Prim.nat8ToNat(1 << pp); let mask : Nat8 = 0xff >> (8 - pp); - return acc + Prim.nat8ToNat(i & mask); + return acc + Prim.nat8ToNat(i & mask) }; - pp -= 8; + pp -= 8 }; - P.unreachable(); + P.unreachable() }; /// Counts the number of heads in `n` coin tosses. /// Seed blob must contain at least ((n+7) / 8) bytes. public func binomialFrom(n : Nat8, seed : Blob) : Nat8 { - binomialIter(n, seed.vals()); + binomialIter(n, seed.vals()) }; // internal worker method, expects iterator with sufficient supply @@ -166,15 +166,15 @@ module { var acc : Nat8 = 0; for (i in it) { if (8 : Nat8 <= nn) { acc +%= Prim.popcntNat8(i) } else if (0 : Nat8 == nn) { - return acc; + return acc } else { let mask : Nat8 = 0xff << (8 - nn); let residue = Prim.popcntNat8(i & mask); - return (acc +% residue); + return (acc +% residue) }; - nn -= 8; + nn -= 8 }; - P.unreachable(); + P.unreachable() } -}; +} diff --git a/src/Result.mo b/src/Result.mo index 451bdc63..68ff6f0b 100644 --- a/src/Result.mo +++ b/src/Result.mo @@ -22,7 +22,7 @@ module { /// ``` public type Result = { #ok : Ok; - #err : Err; + #err : Err }; // Compares two Result's for equality. @@ -30,17 +30,17 @@ module { eqOk : (Ok, Ok) -> Bool, eqErr : (Err, Err) -> Bool, r1 : Result, - r2 : Result, + r2 : Result ) : Bool { switch (r1, r2) { case (#ok(ok1), #ok(ok2)) { - eqOk(ok1, ok2); + eqOk(ok1, ok2) }; case (#err(err1), #err(err2)) { - eqErr(err1, err2); + eqErr(err1, err2) }; - case _ { false }; - }; + case _ { false } + } }; // Compares two Results. `#ok` is larger than `#err`. This ordering is @@ -49,18 +49,18 @@ module { compareOk : (Ok, Ok) -> Order.Order, compareErr : (Err, Err) -> Order.Order, r1 : Result, - r2 : Result, + r2 : Result ) : Order.Order { switch (r1, r2) { case (#ok(ok1), #ok(ok2)) { - compareOk(ok1, ok2); + compareOk(ok1, ok2) }; case (#err(err1), #err(err2)) { - compareErr(err1, err2); + compareErr(err1, err2) }; case (#ok(_), _) { #greater }; - case (#err(_), _) { #less }; - }; + case (#err(_), _) { #less } + } }; /// Allows sequencing of `Result` values and functions that return @@ -83,12 +83,12 @@ module { /// ``` public func chain( x : Result, - y : R1 -> Result, + y : R1 -> Result ) : Result { switch x { case (#err(e)) { #err(e) }; - case (#ok(r)) { y(r) }; - }; + case (#ok(r)) { y(r) } + } }; /// Flattens a nested Result. @@ -100,34 +100,34 @@ module { /// assert(Result.flatten(#ok(#err("Wrong"))) == #err("Wrong")); /// ``` public func flatten( - result : Result, Error>, + result : Result, Error> ) : Result { switch result { case (#ok(ok)) { ok }; - case (#err(err)) { #err(err) }; - }; + case (#err(err)) { #err(err) } + } }; /// Maps the `Ok` type/value, leaving any `Error` type/value unchanged. public func mapOk( x : Result, - f : Ok1 -> Ok2, + f : Ok1 -> Ok2 ) : Result { switch x { case (#err(e)) { #err(e) }; - case (#ok(r)) { #ok(f(r)) }; - }; + case (#ok(r)) { #ok(f(r)) } + } }; /// Maps the `Err` type/value, leaving any `Ok` type/value unchanged. public func mapErr( x : Result, - f : Error1 -> Error2, + f : Error1 -> Error2 ) : Result { switch x { case (#err(e)) { #err(f(e)) }; - case (#ok(r)) { #ok(r) }; - }; + case (#ok(r)) { #ok(r) } + } }; /// Create a result from an option, including an error value to handle the `null` case. @@ -139,8 +139,8 @@ module { public func fromOption(x : ?R, err : E) : Result { switch x { case (?x) { #ok(x) }; - case null { #err(err) }; - }; + case null { #err(err) } + } }; /// Create an option from a result, turning all #err into `null`. @@ -152,8 +152,8 @@ module { public func toOption(r : Result) : ?R { switch r { case (#ok(x)) { ?x }; - case (#err(_)) { null }; - }; + case (#err(_)) { null } + } }; /// Applies a function to a successful value, but discards the result. Use @@ -170,40 +170,40 @@ module { public func iterate(res : Result, f : Ok -> ()) { switch res { case (#ok(ok)) { f(ok) }; - case _ {}; - }; + case _ {} + } }; // Whether this Result is an `#ok` public func isOk(r : Result) : Bool { switch r { case (#ok(_)) { true }; - case (#err(_)) { false }; - }; + case (#err(_)) { false } + } }; // Whether this Result is an `#err` public func isErr(r : Result) : Bool { switch r { case (#ok(_)) { false }; - case (#err(_)) { true }; - }; + case (#err(_)) { true } + } }; /// Asserts that its argument is an `#ok` result, traps otherwise. public func assertOk(r : Result) { switch (r) { case (#err(_)) { assert false }; - case (#ok(_)) {}; - }; + case (#ok(_)) {} + } }; /// Asserts that its argument is an `#err` result, traps otherwise. public func assertErr(r : Result) { switch (r) { case (#err(_)) {}; - case (#ok(_)) assert false; - }; + case (#ok(_)) assert false + } }; -}; +} diff --git a/src/Stack.mo b/src/Stack.mo index 0229115c..cf5d9bff 100644 --- a/src/Stack.mo +++ b/src/Stack.mo @@ -13,28 +13,28 @@ module { /// Push an element on the top of the stack. public func push(x : T) { - stack := ?(x, stack); + stack := ?(x, stack) }; /// True when the stack is empty. public func isEmpty() : Bool { - List.isNil(stack); + List.isNil(stack) }; /// Return and retain the top element, or return null. public func peek() : ?T { switch stack { case null { null }; - case (?(h, t)) { ?h }; - }; + case (?(h, t)) { ?h } + } }; /// Remove and return the top element, or return null. public func pop() : ?T { switch stack { case null { null }; - case (?(h, t)) { stack := t; ?h }; - }; - }; - }; -}; + case (?(h, t)) { stack := t; ?h } + } + } + } +} diff --git a/src/Text.mo b/src/Text.mo index 5a70c676..8f3ca9b0 100644 --- a/src/Text.mo +++ b/src/Text.mo @@ -35,9 +35,9 @@ module { public func fromIter(cs : Iter.Iter) : Text { var r = ""; for (c in cs) { - r #= Prim.charToText(c); + r #= Prim.charToText(c) }; - return r; + return r }; /// Returns `t.size()`, the number of characters in `t` (and `t.chars()`). @@ -50,9 +50,9 @@ module { var x : Nat32 = 5381; for (char in t.chars()) { let c : Nat32 = Prim.charToNat32(char); - x := ((x << 5) +% x) +% c; + x := ((x << 5) +% x) +% c }; - return x; + return x }; /// Returns the concatenation of `t1` and `t2`, `t1 # t2`. @@ -79,7 +79,7 @@ module { /// Returns the order of `t1` and `t2`. public func compare(t1 : Text, t2 : Text) : { #less; #equal; #greater } { let c = Prim.textCompare(t1, t2); - if (c < 0) #less else if (c == 0) #equal else #greater; + if (c < 0) #less else if (c == 0) #equal else #greater }; private func extract(t : Text, i : Nat, j : Nat) : Text { @@ -91,17 +91,17 @@ module { var n = i; while (n > 0) { ignore cs.next(); - n -= 1; + n -= 1 }; n := j; while (n > 0) { switch (cs.next()) { case null { assert false }; - case (?c) { r #= Prim.charToText(c) }; + case (?c) { r #= Prim.charToText(c) } }; - n -= 1; + n -= 1 }; - return r; + return r }; /// Returns the concatenation of text values in `ts`, separated by `sep`. @@ -109,44 +109,44 @@ module { var r = ""; if (sep.size() == 0) { for (t in ts) { - r #= t; + r #= t }; - return r; + return r }; let next = ts.next; switch (next()) { case null { return r }; case (?t) { - r #= t; - }; + r #= t + } }; loop { switch (next()) { case null { return r }; case (?t) { r #= sep; - r #= t; - }; - }; - }; + r #= t + } + } + } }; /// Returns the result of applying `f` to each character in `ts`, concatenating the intermediate single-character text values. public func map(t : Text, f : Char -> Char) : Text { var r = ""; for (c in t.chars()) { - r #= Prim.charToText(f(c)); + r #= Prim.charToText(f(c)) }; - return r; + return r }; /// Returns the result of applying `f` to each character in `ts`, concatenating the intermediate text values. public func translate(t : Text, f : Char -> Text) : Text { var r = ""; for (c in t.chars()) { - r #= f(c); + r #= f(c) }; - return r; + return r }; /// A pattern `p` describes a sequence of characters. A pattern has one of the following forms: @@ -159,7 +159,7 @@ module { public type Pattern = { #char : Char; #text : Text; - #predicate : (Char -> Bool); + #predicate : (Char -> Bool) }; private func take(n : Nat, cs : Iter.Iter) : Iter.Iter { @@ -168,15 +168,15 @@ module { public func next() : ?Char { if (i == 0) return null; i -= 1; - return cs.next(); - }; - }; + return cs.next() + } + } }; private func empty() : Iter.Iter { object { - public func next() : ?Char = null; - }; + public func next() : ?Char = null + } }; private type Match = { @@ -185,14 +185,14 @@ module { /// #fail(cs,c) on partial match of cs, but failing match on c #fail : (cs : Iter.Iter, c : Char); /// #empty(cs) on partial match of cs and empty stream - #empty : (cs : Iter.Iter); + #empty : (cs : Iter.Iter) }; private func sizeOfPattern(pat : Pattern) : Nat { switch pat { case (#text(t)) { t.size() }; - case (#predicate(_) or #char(_)) { 1 }; - }; + case (#predicate(_) or #char(_)) { 1 } + } }; private func matchOfPattern(pat : Pattern) : (cs : Iter.Iter) -> Match { @@ -202,28 +202,28 @@ module { switch (cs.next()) { case (?c) { if (p == c) { - #success; + #success } else { - #fail(empty(), c); - }; + #fail(empty(), c) + } }; - case null { #empty(empty()) }; - }; - }; + case null { #empty(empty()) } + } + } }; case (#predicate(p)) { func(cs : Iter.Iter) : Match { switch (cs.next()) { case (?c) { if (p(c)) { - #success; + #success } else { - #fail(empty(), c); - }; + #fail(empty(), c) + } }; - case null { #empty(empty()) }; - }; - }; + case null { #empty(empty()) } + } + } }; case (#text(p)) { func(cs : Iter.Iter) : Match { @@ -235,21 +235,21 @@ module { switch (cs.next()) { case (?c) { if (c != d) { - return #fail(take(i, p.chars()), c); + return #fail(take(i, p.chars()), c) }; - i += 1; + i += 1 }; case null { - return #empty(take(i, p.chars())); - }; - }; + return #empty(take(i, p.chars())) + } + } }; - case null { return #success }; - }; - }; - }; - }; - }; + case null { return #success } + } + } + } + } + } }; private class CharBuffer(cs : Iter.Iter) : Iter.Iter = { @@ -257,7 +257,7 @@ module { var stack : Stack.Stack<(Iter.Iter, Char)> = Stack.Stack(); public func pushBack(cs0 : Iter.Iter, c : Char) { - stack.push((cs0, c)); + stack.push((cs0, c)) }; public func next() : ?Char { @@ -266,18 +266,18 @@ module { switch (buff.next()) { case null { ignore stack.pop(); - return ?c; + return ?c }; case oc { - return oc; - }; - }; + return oc + } + } }; case null { - return cs.next(); - }; - }; - }; + return cs.next() + } + } + } }; /// Returns the sequence of fields in `t`, derived from start to end, @@ -298,44 +298,44 @@ module { let r = field; field := ""; state := 1; - return ?r; + return ?r }; case (#empty(cs1)) { for (c in cs1) { - field #= fromChar(c); + field #= fromChar(c) }; let r = if (state == 0 and field == "") { - null; + null } else { - ?field; + ?field }; state := 2; - return r; + return r }; case (#fail(cs1, c)) { cs.pushBack(cs1, c); switch (cs.next()) { case (?ci) { - field #= fromChar(ci); + field #= fromChar(ci) }; case null { let r = if (state == 0 and field == "") { - null; + null } else { - ?field; + ?field }; state := 2; - return r; - }; - }; - }; - }; - }; + return r + } + } + } + } + } }; - case _ { return null }; - }; - }; - }; + case _ { return null } + } + } + } }; /// Returns the sequence of tokens in `t`, derived from start to end. @@ -347,10 +347,10 @@ module { public func next() : ?Text { switch (fs.next()) { case (?"") { next() }; - case ot { ot }; - }; - }; - }; + case ot { ot } + } + } + } }; /// Returns true if `t` contains a match for pattern `p`. @@ -360,22 +360,22 @@ module { loop { switch (match(cs)) { case (#success) { - return true; + return true }; case (#empty(cs1)) { - return false; + return false }; case (#fail(cs1, c)) { cs.pushBack(cs1, c); switch (cs.next()) { case null { - return false; + return false }; case _ {}; // continue - }; - }; - }; - }; + } + } + } + } }; /// Returns `true` if `t` starts with a prefix matching pattern `p`, otherwise returns `false`. @@ -384,8 +384,8 @@ module { let match = matchOfPattern(p); switch (match(cs)) { case (#success) { true }; - case _ { false }; - }; + case _ { false } + } }; /// Returns `true` if `t` ends with a suffix matching pattern `p`, otherwise returns `false`. @@ -399,12 +399,12 @@ module { var diff : Nat = s1 - s2; while (diff > 0) { ignore cs1.next(); - diff -= 1; + diff -= 1 }; switch (match(cs1)) { case (#success) { true }; - case _ { false }; - }; + case _ { false } + } }; /// Returns `t` with all matches of pattern `p` replaced by text `r`. @@ -418,29 +418,29 @@ module { case (#success) { res #= r; if (size > 0) { - continue l; - }; + continue l + } }; case (#empty(cs1)) { for (c1 in cs1) { - res #= fromChar(c1); + res #= fromChar(c1) }; - break l; + break l }; case (#fail(cs1, c)) { - cs.pushBack(cs1, c); - }; + cs.pushBack(cs1, c) + } }; switch (cs.next()) { case null { - break l; + break l }; case (?c1) { - res #= fromChar(c1); + res #= fromChar(c1) }; // continue - }; + } }; - return res; + return res }; /// Returns the optioned suffix of `t` obtained by eliding exactly one leading match of pattern `p`, otherwise `null`. @@ -451,8 +451,8 @@ module { let match = matchOfPattern(p); switch (match(cs)) { case (#success) return ?fromIter(cs); - case _ return null; - }; + case _ return null + } }; /// Returns the optioned prefix of `t` obtained by eliding exactly one trailing match of pattern `p`, otherwise `null`. @@ -466,12 +466,12 @@ module { var diff : Nat = s1 - s2; while (diff > 0) { ignore cs1.next(); - diff -= 1; + diff -= 1 }; switch (match(cs1)) { case (#success) return ?extract(t, 0, s1 - s2); - case _ return null; - }; + case _ return null + } }; /// Returns the suffix of `t` obtained by eliding all leading matches of pattern `p`. @@ -484,24 +484,24 @@ module { loop { switch (match(cs)) { case (#success) { - matchSize += size; + matchSize += size }; // continue case (#empty(cs1)) { return if (matchSize == 0) { - t; + t } else { - fromIter(cs1); - }; + fromIter(cs1) + } }; case (#fail(cs1, c)) { return if (matchSize == 0) { - t; + t } else { - fromIter(cs1) # fromChar(c) # fromIter(cs); - }; - }; - }; - }; + fromIter(cs1) # fromChar(c) # fromIter(cs) + } + } + } + } }; /// Returns the prefix of `t` obtained by eliding all trailing matches of pattern `p`. @@ -514,22 +514,22 @@ module { label l loop { switch (match(cs)) { case (#success) { - matchSize += size; + matchSize += size }; // continue case (#empty(cs1)) { switch (cs1.next()) { case null break l; - case (?_) return t; - }; + case (?_) return t + } }; case (#fail(cs1, c)) { matchSize := 0; cs.pushBack(cs1, c); - ignore cs.next(); - }; - }; + ignore cs.next() + } + } }; - extract(t, 0, t.size() - matchSize); + extract(t, 0, t.size() - matchSize) }; /// Returns the subtext of `t` obtained by eliding all leading and trailing matches of pattern `p`. @@ -542,10 +542,10 @@ module { loop { switch (match(cs)) { case (#success) { - matchSize += size; + matchSize += size }; // continue case (#empty(cs1)) { - return if (matchSize == 0) { t } else { fromIter(cs1) }; + return if (matchSize == 0) { t } else { fromIter(cs1) } }; case (#fail(cs1, c)) { let start = matchSize; @@ -556,32 +556,32 @@ module { label l loop { switch (match(cs2)) { case (#success) { - matchSize += size; + matchSize += size }; // continue case (#empty(cs3)) { switch (cs1.next()) { case null break l; - case (?_) return t; - }; + case (?_) return t + } }; case (#fail(cs3, c1)) { matchSize := 0; cs2.pushBack(cs3, c1); - ignore cs2.next(); - }; - }; + ignore cs2.next() + } + } }; - return extract(t, start, t.size() - matchSize - start); - }; - }; - }; + return extract(t, start, t.size() - matchSize - start) + } + } + } }; /// Returns the lexicographic comparison of `t1` and `t2`, using the given character ordering `cmp`. public func compareWith( t1 : Text, t2 : Text, - cmp : (Char, Char) -> { #less; #equal; #greater }, + cmp : (Char, Char) -> { #less; #equal; #greater } ) : { #less; #equal; #greater } { let cs1 = t1.chars(); let cs2 = t2.chars(); @@ -593,11 +593,11 @@ module { case (?c1, ?c2) { switch (cmp(c1, c2)) { case (#equal) {}; // continue - case other { return other }; - }; - }; - }; - }; + case other { return other } + } + } + } + } }; /// Returns the UTF-8 encoding of the given text @@ -605,5 +605,5 @@ module { /// Tries to decode the given `Blob` as UTF-8. /// Returns `null` if the blob is _not_ valid UTF-8. - public let decodeUtf8 : Blob -> ?Text = Prim.decodeUtf8; -}; + public let decodeUtf8 : Blob -> ?Text = Prim.decodeUtf8 +} diff --git a/src/Time.mo b/src/Time.mo index 282990c2..940ff30d 100644 --- a/src/Time.mo +++ b/src/Time.mo @@ -33,4 +33,4 @@ module { /// }; /// }; /// ``` -}; +} diff --git a/src/Trie.mo b/src/Trie.mo index d00809e9..85f0175b 100644 --- a/src/Trie.mo +++ b/src/Trie.mo @@ -94,13 +94,13 @@ module { public type Trie = { #empty; #leaf : Leaf; - #branch : Branch; + #branch : Branch }; /// Leaf nodes of trie consist of key-value pairs as a list. public type Leaf = { size : Nat; - keyvals : AssocList, V>; + keyvals : AssocList, V> }; /// Branch nodes of the trie discriminate on a bit position of the keys' hashes. @@ -109,7 +109,7 @@ module { public type Branch = { size : Nat; left : Trie; - right : Trie; + right : Trie }; public type AssocList = AssocList.AssocList; @@ -119,7 +119,7 @@ module { /// `hash` permits fast inequality checks, and permits collisions hash : Hash.Hash; /// `key` permits precise equality checks, but only used after equal hashes. - key : K; + key : K }; type List = List.List; @@ -127,8 +127,8 @@ module { /// Equality function for two `Key`s, in terms of equality of `K`'s. public func equalKey(keq : (K, K) -> Bool) : ((Key, Key) -> Bool) { func(key1 : Key, key2 : Key) : Bool { - Hash.equal(key1.hash, key2.hash) and keq(key1.key, key2.key); - }; + Hash.equal(key1.hash, key2.hash) and keq(key1.key, key2.key) + } }; /// @deprecated `isValid` is an internal predicate and will be removed in future. @@ -136,28 +136,28 @@ module { func rec(t : Trie, bitpos : ?Hash.Hash, bits : Hash.Hash, mask : Hash.Hash) : Bool { switch t { case (#empty) { - true; + true }; case (#leaf(l)) { let len = List.size(l.keyvals); len <= MAX_LEAF_SIZE and len == l.size and List.all( l.keyvals, - func((k : Key, v : V)) : Bool { ((k.hash & mask) == bits) }, - ); + func((k : Key, v : V)) : Bool { ((k.hash & mask) == bits) } + ) }; case (#branch(b)) { let bitpos1 = switch bitpos { case null { Prim.natToNat32(0) }; - case (?bp) { Prim.natToNat32(Prim.nat32ToNat(bp) + 1) }; + case (?bp) { Prim.natToNat32(Prim.nat32ToNat(bp) + 1) } }; let mask1 = mask | (Prim.natToNat32(1) << bitpos1); let bits1 = bits | (Prim.natToNat32(1) << bitpos1); let sum = size(b.left) + size(b.right); - (b.size == sum) and rec(b.left, ?bitpos1, bits, mask1) and rec(b.right, ?bitpos1, bits1, mask1); - }; - }; + (b.size == sum) and rec(b.left, ?bitpos1, bits, mask1) and rec(b.right, ?bitpos1, bits1, mask1) + } + } }; - rec(t, null, 0, 0); + rec(t, null, 0, 0) }; /// A 2D trie maps dimension-1 keys to another @@ -178,8 +178,8 @@ module { switch t { case (#empty) { 0 }; case (#leaf(l)) { l.size }; - case (#branch(b)) { b.size }; - }; + case (#branch(b)) { b.size } + } }; /// Construct a branch node, computing the size stored there. @@ -188,8 +188,8 @@ module { #branch { size = sum; left = l; - right = r; - }; + right = r + } }; /// Construct a leaf node, computing the size stored there. @@ -198,7 +198,7 @@ module { /// by constructing branches as necessary; to do so, it also needs the bitpos /// of the leaf. public func leaf(kvs : AssocList, V>, bitpos : Nat) : Trie { - fromList(null, kvs, bitpos); + fromList(null, kvs, bitpos) }; module ListUtil { @@ -211,12 +211,12 @@ module { switch l { case null { ?i }; case (?(_, t)) { - if (i >= max) { null } else { rec(t, max, i + 1) }; - }; - }; + if (i >= max) { null } else { rec(t, max, i + 1) } + } + } }; - rec(l, max, 0); - }; + rec(l, max, 0) + } }; /// Transform a list into a trie, splitting input list into small (leaf) lists, if necessary. @@ -227,33 +227,33 @@ module { switch (ListUtil.lenClamp(kvs, MAX_LEAF_SIZE)) { case null {} /* fall through to branch case. */; case (?len) { - return #leaf({ size = len; keyvals = kvs }); - }; - }; + return #leaf({ size = len; keyvals = kvs }) + } + } }; case (?c) { if (c == 0) { - return #empty; + return #empty } else if (c <= MAX_LEAF_SIZE) { - return #leaf({ size = c; keyvals = kvs }); + return #leaf({ size = c; keyvals = kvs }) } else { //fall through to branch case - }; - }; + } + } }; let (ls, l, rs, r) = splitList(kvs, bitpos); if (ls == 0 and rs == 0) { - #empty; + #empty } else if (rs == 0 and ls <= MAX_LEAF_SIZE) { - #leaf({ size = ls; keyvals = l }); + #leaf({ size = ls; keyvals = l }) } else if (ls == 0 and rs <= MAX_LEAF_SIZE) { - #leaf({ size = rs; keyvals = r }); + #leaf({ size = rs; keyvals = r }) } else { - branch(rec(?ls, l, bitpos + 1), rec(?rs, r, bitpos + 1)); - }; + branch(rec(?ls, l, bitpos + 1), rec(?rs, r, bitpos + 1)) + } }; - rec(kvc, kvs, bitpos); + rec(kvc, kvs, bitpos) }; /// Clone the trie efficiently, via sharing. @@ -269,33 +269,33 @@ module { switch t { case (#empty) { let (kvs, _) = AssocList.replace(null, k, key_eq, v); - (leaf(kvs, bitpos), null); + (leaf(kvs, bitpos), null) }; case (#branch(b)) { let bit = Hash.bit(k.hash, bitpos); // rebuild either the left or right path with the (k, v) pair if (not bit) { let (l, v_) = rec(b.left, bitpos + 1); - (branch(l, b.right), v_); + (branch(l, b.right), v_) } else { let (r, v_) = rec(b.right, bitpos + 1); - (branch(b.left, r), v_); - }; + (branch(b.left, r), v_) + } }; case (#leaf(l)) { let (kvs2, old_val) = AssocList.replace(l.keyvals, k, key_eq, v); - (leaf(kvs2, bitpos), old_val); - }; - }; + (leaf(kvs2, bitpos), old_val) + } + } }; let (to, vo) = rec(t, 0); //assert(isValid(to, false)); - (to, vo); + (to, vo) }; /// Put the given key's value in the trie; return the new trie, and the previous value associated with the key, if any public func put(t : Trie, k : Key, k_eq : (K, K) -> Bool, v : V) : (Trie, ?V) { - replace(t, k, k_eq, ?v); + replace(t, k, k_eq, ?v) }; /// Get the value of the given key in the trie, or return null if nonexistent @@ -308,28 +308,28 @@ module { switch t { case (#empty) { null }; case (#leaf(l)) { - AssocList.find(l.keyvals, k, key_eq); + AssocList.find(l.keyvals, k, key_eq) }; case (#branch(b)) { let bit = Hash.bit(k.hash, bitpos); if (not bit) { - rec(b.left, bitpos + 1); + rec(b.left, bitpos + 1) } else { - rec(b.right, bitpos + 1); - }; - }; - }; + rec(b.right, bitpos + 1) + } + } + } }; - rec(t, 0); + rec(t, 0) }; func splitAssocList(al : AssocList, V>, bitpos : Nat) : (AssocList, V>, AssocList, V>) { List.partition( al, func((k : Key, v : V)) : Bool { - not Hash.bit(k.hash, bitpos); - }, - ); + not Hash.bit(k.hash, bitpos) + } + ) }; func splitList(l : AssocList, V>, bitpos : Nat) : (Nat, AssocList, V>, Nat, AssocList, V>) { @@ -339,12 +339,12 @@ module { case (?((k, v), t)) { let (cl, l, cr, r) = rec(t); if (not Hash.bit(k.hash, bitpos)) { (cl + 1, ?((k, v), l), cr, r) } else { - (cl, l, cr + 1, ?((k, v), r)); - }; - }; - }; + (cl, l, cr + 1, ?((k, v), r)) + } + } + } }; - rec(l); + rec(l) }; /// Merge tries, preferring the left trie where there are collisions @@ -369,30 +369,30 @@ module { switch (x, y) { case (null, null) { P.unreachable() }; case (null, ?v) { v }; - case (?v, _) { v }; - }; - }, + case (?v, _) { v } + } + } ), - bitpos, - ); + bitpos + ) }; case (#leaf(l), _) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr); + rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr) }; case (_, #leaf(l)) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))); + rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))) }; case (#branch(b1), #branch(b2)) { branch( rec(bitpos + 1, b1.left, b2.left), - rec(bitpos + 1, b1.right, b2.right), - ); - }; - }; + rec(bitpos + 1, b1.right, b2.right) + ) + } + } }; - rec(0, tl, tr); + rec(0, tl, tr) }; /// Merge tries like `merge`, except signals a @@ -414,30 +414,30 @@ module { switch (x, y) { case (null, ?v) { v }; case (?v, null) { v }; - case (_, _) { P.unreachable() }; - }; - }, + case (_, _) { P.unreachable() } + } + } ), - bitpos, - ); + bitpos + ) }; case (#leaf(l), _) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr); + rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr) }; case (_, #leaf(l)) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))); + rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))) }; case (#branch(b1), #branch(b2)) { branch( rec(bitpos + 1, b1.left, b2.left), - rec(bitpos + 1, b1.right, b2.right), - ); - }; - }; + rec(bitpos + 1, b1.right, b2.right) + ) + } + } }; - rec(0, tl, tr); + rec(0, tl, tr) }; /// Difference of tries. The output consists are pairs of @@ -455,28 +455,28 @@ module { AssocList.diff( l1.keyvals, l2.keyvals, - key_eq, + key_eq ), - bitpos, - ); + bitpos + ) }; case (#leaf(l), _) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr); + rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr) }; case (_, #leaf(l)) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))); + rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))) }; case (#branch(b1), #branch(b2)) { branch( rec(bitpos + 1, b1.left, b2.left), - rec(bitpos + 1, b1.right, b2.right), - ); - }; - }; + rec(bitpos + 1, b1.right, b2.right) + ) + } + } }; - rec(0, tl, tr); + rec(0, tl, tr) }; /// Map disjunction. @@ -497,7 +497,7 @@ module { tl : Trie, tr : Trie, k_eq : (K, K) -> Bool, - vbin : (?V, ?W) -> X, + vbin : (?V, ?W) -> X ) : Trie { let key_eq = equalKey(k_eq); @@ -506,15 +506,15 @@ module { switch t { case (#empty) { #empty }; case (#leaf(l)) { - leaf(AssocList.disj(l.keyvals, null, key_eq, vbin), bitpos); + leaf(AssocList.disj(l.keyvals, null, key_eq, vbin), bitpos) }; case (#branch(b)) { branch( recL(b.left, bitpos + 1), - recL(b.right, bitpos + 1), - ); - }; - }; + recL(b.right, bitpos + 1) + ) + } + } }; /* empty left case; build from right only: */ @@ -522,15 +522,15 @@ module { switch t { case (#empty) { #empty }; case (#leaf(l)) { - leaf(AssocList.disj(null, l.keyvals, key_eq, vbin), bitpos); + leaf(AssocList.disj(null, l.keyvals, key_eq, vbin), bitpos) }; case (#branch(b)) { branch( recR(b.left, bitpos + 1), - recR(b.right, bitpos + 1), - ); - }; - }; + recR(b.right, bitpos + 1) + ) + } + } }; /* main recursion */ @@ -540,26 +540,26 @@ module { case (#empty, _) { recR(tr, bitpos) }; case (_, #empty) { recL(tl, bitpos) }; case (#leaf(l1), #leaf(l2)) { - leaf(AssocList.disj(l1.keyvals, l2.keyvals, key_eq, vbin), bitpos); + leaf(AssocList.disj(l1.keyvals, l2.keyvals, key_eq, vbin), bitpos) }; case (#leaf(l), _) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr); + rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr) }; case (_, #leaf(l)) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))); + rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))) }; case (#branch(b1), #branch(b2)) { branch( rec(bitpos + 1, b1.left, b2.left), - rec(bitpos + 1, b1.right, b2.right), - ); - }; - }; + rec(bitpos + 1, b1.right, b2.right) + ) + } + } }; - rec(0, tl, tr); + rec(0, tl, tr) }; /// Map join. @@ -574,7 +574,7 @@ module { tl : Trie, tr : Trie, k_eq : (K, K) -> Bool, - vbin : (V, W) -> X, + vbin : (V, W) -> X ) : Trie { let key_eq = equalKey(k_eq); @@ -583,26 +583,26 @@ module { case (#empty, _) { #empty }; case (_, #empty) { #empty }; case (#leaf(l1), #leaf(l2)) { - leaf(AssocList.join(l1.keyvals, l2.keyvals, key_eq, vbin), bitpos); + leaf(AssocList.join(l1.keyvals, l2.keyvals, key_eq, vbin), bitpos) }; case (#leaf(l), _) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr); + rec(bitpos, branch(leaf(ll, bitpos), leaf(lr, bitpos)), tr) }; case (_, #leaf(l)) { let (ll, lr) = splitAssocList(l.keyvals, bitpos); - rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))); + rec(bitpos, tl, branch(leaf(ll, bitpos), leaf(lr, bitpos))) }; case (#branch(b1), #branch(b2)) { branch( rec(bitpos + 1, b1.left, b2.left), - rec(bitpos + 1, b1.right, b2.right), - ); - }; - }; + rec(bitpos + 1, b1.right, b2.right) + ) + } + } }; - rec(0, tl, tr); + rec(0, tl, tr) }; /// This operation gives a recursor for the internal structure of @@ -617,13 +617,13 @@ module { AssocList.fold( l.keyvals, empty, - func(k : Key, v : V, x : X) : X { bin(leaf(k.key, v), x) }, - ); + func(k : Key, v : V, x : X) : X { bin(leaf(k.key, v), x) } + ) }; - case (#branch(b)) { bin(rec(b.left), rec(b.right)) }; - }; + case (#branch(b)) { bin(rec(b.left), rec(b.right)) } + } }; - rec(t); + rec(t) }; /// Map product. @@ -641,7 +641,7 @@ module { tl : Trie, tr : Trie, op : (K1, V1, K2, V2) -> ?(Key, V3), - k3_eq : (K3, K3) -> Bool, + k3_eq : (K3, K3) -> Bool ) : Trie { /*- binary case: merge disjoint results: */ @@ -658,14 +658,14 @@ module { func(k2 : K2, v2 : V2) : Trie { switch (op(k1, v1, k2, v2)) { case null { #empty }; - case (?(k3, v3)) { (put(#empty, k3, k3_eq, v3)).0 }; - }; + case (?(k3, v3)) { (put(#empty, k3, k3_eq, v3)).0 } + } }, - #empty, - ); + #empty + ) }, - #empty, - ); + #empty + ) }; /// Returns an `Iter` over the key-value entries of the trie. @@ -681,25 +681,25 @@ module { switch trie { case (#empty) { stack := stack2; - next(); + next() }; case (#leaf({ keyvals = null })) { stack := stack2; - next(); + next() }; case (#leaf({ size = c; keyvals = ?((k, v), kvs) })) { stack := ?(#leaf({ size = c -1; keyvals = kvs }), stack2); - ?(k.key, v); + ?(k.key, v) }; case (#branch(br)) { stack := ?(br.left, ?(br.right, stack2)); - next(); - }; - }; - }; - }; - }; - }; + next() + } + } + } + } + } + } }; /// Represent the construction of tries as data. @@ -727,8 +727,8 @@ module { #seq : { size : Nat; left : Build; - right : Build; - }; + right : Build + } }; /// Size of the build, measured in `#put` operations @@ -736,14 +736,14 @@ module { switch tb { case (#skip) { 0 }; case (#put(_, _, _)) { 1 }; - case (#seq(seq)) { seq.size }; - }; + case (#seq(seq)) { seq.size } + } }; /// Build sequence of two sub-builds public func seq(l : Build, r : Build) : Build { let sum = size(l) + size(r); - #seq({ size = sum; left = l; right = r }); + #seq({ size = sum; left = l; right = r }) }; /// Like [`prod`](#prod), except do not actually do the put calls, just @@ -753,15 +753,15 @@ module { tl : Trie, tr : Trie, op : (K1, V1, K2, V2) -> ?(K3, V3), - k3_eq : (K3, K3) -> Bool, + k3_eq : (K3, K3) -> Bool ) : Build { func outer_bin(a : Build, b : Build) : Build { - seq(a, b); + seq(a, b) }; func inner_bin(a : Build, b : Build) : Build { - seq(a, b); + seq(a, b) }; /// double-nested folds @@ -775,14 +775,14 @@ module { func(k2 : K2, v2 : V2) : Build { switch (op(k1, v1, k2, v2)) { case null { #skip }; - case (?(k3, v3)) { #put(k3, null, v3) }; - }; + case (?(k3, v3)) { #put(k3, null, v3) } + } }, - #skip, - ); + #skip + ) }, - #skip, - ); + #skip + ) }; /// Project the nth key-value pair from the trie build. @@ -794,21 +794,21 @@ module { case (#skip) { P.unreachable() }; case (#put(k, h, v)) { assert (i == 0); - ?(k, h, v); + ?(k, h, v) }; case (#seq(s)) { let size_left = size(s.left); if (i < size_left) { rec(s.left, i) } else { - rec(s.right, i - size_left); - }; - }; - }; + rec(s.right, i - size_left) + } + } + } }; if (i >= size(tb)) { - return null; + return null }; - rec(tb, i); + rec(tb, i) }; /// Like [`mergeDisjoint`](#mergedisjoint), except that it avoids the @@ -818,11 +818,11 @@ module { foldUp( t, func(t1 : Build, t2 : Build) : Build { - seq(t1, t2); + seq(t1, t2) }, func(_ : K1, t : Build) : Build { t }, - #skip, - ); + #skip + ) }; /// Gather the collection of key-value pairs into an array of a (possibly-distinct) type. @@ -834,8 +834,8 @@ module { switch tb { case (#skip) {}; case (#put(k, _, v)) { a[i] := ?f(k, v); i := i + 1 }; - case (#seq(s)) { rec(s.left); rec(s.right) }; - }; + case (#seq(s)) { rec(s.left); rec(s.right) } + } }; rec(tb); A.tabulate( @@ -843,10 +843,10 @@ module { func(i : Nat) : W { switch (a[i]) { case null { P.unreachable() }; - case (?x) { x }; - }; - }, - ); + case (?x) { x } + } + } + ) }; }; @@ -861,13 +861,13 @@ module { AssocList.fold( l.keyvals, x, - func(k : Key, v : V, x : X) : X = f(k.key, v, x), - ); + func(k : Key, v : V, x : X) : X = f(k.key, v, x) + ) }; - case (#branch(b)) { rec(b.left, rec(b.right, x)) }; - }; + case (#branch(b)) { rec(b.left, rec(b.right, x)) } + } }; - rec(t, x); + rec(t, x) }; /// Test whether a given key-value pair is present, or not. @@ -878,13 +878,13 @@ module { case (#leaf(l)) { List.some( l.keyvals, - func((k : Key, v : V)) : Bool = f(k.key, v), - ); + func((k : Key, v : V)) : Bool = f(k.key, v) + ) }; - case (#branch(b)) { rec(b.left) or rec(b.right) }; - }; + case (#branch(b)) { rec(b.left) or rec(b.right) } + } }; - rec(t); + rec(t) }; /// Test whether all key-value pairs have a given property. @@ -895,13 +895,13 @@ module { case (#leaf(l)) { List.all( l.keyvals, - func((k : Key, v : V)) : Bool = f(k.key, v), - ); + func((k : Key, v : V)) : Bool = f(k.key, v) + ) }; - case (#branch(b)) { rec(b.left) and rec(b.right) }; - }; + case (#branch(b)) { rec(b.left) and rec(b.right) } + } }; - rec(t); + rec(t) }; /// Project the nth key-value pair from the trie. @@ -916,15 +916,15 @@ module { case (#branch(b)) { let size_left = size(b.left); if (i < size_left) { rec(b.left, i) } else { - rec(b.right, i - size_left); - }; - }; - }; + rec(b.right, i - size_left) + } + } + } }; if (i >= size(t)) { - return null; + return null }; - rec(t, i); + rec(t, i) }; /// Gather the collection of key-value pairs into an array of a (possibly-distinct) type. @@ -934,19 +934,19 @@ module { func(i : Nat) : W { let (k, v) = switch (nth(t, i)) { case null { P.unreachable() }; - case (?x) { x }; + case (?x) { x } }; - f(k.key, v); - }, + f(k.key, v) + } ); - a; + a }; /// Test for "deep emptiness": subtrees that have branching structure, /// but no leaves. These can result from naive filtering operations; /// filter uses this function to avoid creating such subtrees. public func isEmpty(t : Trie) : Bool { - size(t) == 0; + size(t) == 0 }; /// Filter the key-value pairs by a given predicate. @@ -958,23 +958,23 @@ module { leaf( List.filter( l.keyvals, - func((k : Key, v : V)) : Bool = f(k.key, v), + func((k : Key, v : V)) : Bool = f(k.key, v) ), - bitpos, - ); + bitpos + ) }; case (#branch(b)) { let fl = rec(b.left, bitpos + 1); let fr = rec(b.right, bitpos + 1); if (isEmpty(fl) and isEmpty(fr)) { - #empty; + #empty } else { - branch(fl, fr); - }; - }; - }; + branch(fl, fr) + } + } + } }; - rec(t, 0); + rec(t, 0) }; /// Map and filter the key-value pairs by a given predicate. @@ -990,26 +990,26 @@ module { func((k : Key, v : V)) : ?(Key, W) { switch (f(k.key, v)) { case null { null }; - case (?w) { ?({ key = k.key; hash = k.hash }, w) }; - }; - }, + case (?w) { ?({ key = k.key; hash = k.hash }, w) } + } + } ), - bitpos, - ); + bitpos + ) }; case (#branch(b)) { let fl = rec(b.left, bitpos + 1); let fr = rec(b.right, bitpos + 1); if (isEmpty(fl) and isEmpty(fr)) { - #empty; + #empty } else { - branch(fl, fr); - }; - }; - }; + branch(fl, fr) + } + } + } }; - rec(t, 0); + rec(t, 0) }; /// Test for equality, but naively, based on structure. @@ -1023,7 +1023,7 @@ module { tl : Trie, tr : Trie, keq : (K, K) -> Bool, - veq : (V, V) -> Bool, + veq : (V, V) -> Bool ) : Bool { func rec(tl : Trie, tr : Trie) : Bool { switch (tl, tr) { @@ -1032,16 +1032,16 @@ module { List.equal( l1.keyvals, l2.keyvals, - func((k1 : Key, v1 : V), (k2 : Key, v2 : V)) : Bool = keq(k1.key, k2.key) and veq(v1, v2), - ); + func((k1 : Key, v1 : V), (k2 : Key, v2 : V)) : Bool = keq(k1.key, k2.key) and veq(v1, v2) + ) }; case (#branch(b1), #branch(b2)) { - rec(b1.left, b2.left) and rec(b2.right, b2.right); + rec(b1.left, b2.left) and rec(b2.right, b2.right) }; - case _ { false }; - }; + case _ { false } + } }; - rec(tl, tr); + rec(tl, tr) }; /// Replace the given key's value in the trie, @@ -1053,13 +1053,13 @@ module { k_eq : (K, K) -> Bool, v2 : V, success : (Trie, V) -> X, - fail : () -> X, + fail : () -> X ) : X { let (t2, ov) = replace(t, k, k_eq, ?v2); switch ov { case null { /* no prior value; failure to remove */ fail() }; - case (?v1) { success(t2, v1) }; - }; + case (?v1) { success(t2, v1) } + } }; /// Put the given key's value in the trie; return the new trie; assert that no prior value is associated with the key @@ -1067,9 +1067,9 @@ module { let (t2, none) = replace(t, k, k_eq, ?v); switch none { case null {}; - case (?_) assert false; + case (?_) assert false }; - t2; + t2 }; /// Put the given key's value in the 2D trie; return the new 2D trie. @@ -1079,15 +1079,15 @@ module { k1_eq : (K1, K1) -> Bool, k2 : Key, k2_eq : (K2, K2) -> Bool, - v : V, + v : V ) : Trie2D { let inner = find(t, k1, k1_eq); let (updated_inner, _) = switch inner { case null { put(#empty, k2, k2_eq, v) }; - case (?inner) { put(inner, k2, k2_eq, v) }; + case (?inner) { put(inner, k2, k2_eq, v) } }; let (updated_outer, _) = put(t, k1, k1_eq, updated_inner); - updated_outer; + updated_outer }; /// Put the given key's value in the trie; return the new trie; @@ -1099,7 +1099,7 @@ module { k2_eq : (K2, K2) -> Bool, k3 : Key, k3_eq : (K3, K3) -> Bool, - v : V, + v : V ) : Trie3D { let inner1 = find(t, k1, k1_eq); let (updated_inner1, _) = switch inner1 { @@ -1108,25 +1108,25 @@ module { #empty, k2, k2_eq, - (put(#empty, k3, k3_eq, v)).0, - ); + (put(#empty, k3, k3_eq, v)).0 + ) }; case (?inner1) { let inner2 = find(inner1, k2, k2_eq); let (updated_inner2, _) = switch inner2 { case null { put(#empty, k3, k3_eq, v) }; - case (?inner2) { put(inner2, k3, k3_eq, v) }; + case (?inner2) { put(inner2, k3, k3_eq, v) } }; - put(inner1, k2, k2_eq, updated_inner2); - }; + put(inner1, k2, k2_eq, updated_inner2) + } }; let (updated_outer, _) = put(t, k1, k1_eq, updated_inner1); - updated_outer; + updated_outer }; /// Remove the given key's value in the trie; return the new trie public func remove(t : Trie, k : Key, k_eq : (K, K) -> Bool) : (Trie, ?V) { - replace(t, k, k_eq, null); + replace(t, k, k_eq, null) }; /// Remove the given key's value in the trie, @@ -1137,13 +1137,13 @@ module { k : Key, k_eq : (K, K) -> Bool, success : (Trie, V) -> X, - fail : () -> X, + fail : () -> X ) : X { let (t2, ov) = replace(t, k, k_eq, null); switch ov { case null { /* no prior value; failure to remove */ fail() }; - case (?v) { success(t2, v) }; - }; + case (?v) { success(t2, v) } + } }; /// remove the given key-key pair's value in the 2D trie; return the @@ -1153,16 +1153,16 @@ module { k1 : Key, k1_eq : (K1, K1) -> Bool, k2 : Key, - k2_eq : (K2, K2) -> Bool, + k2_eq : (K2, K2) -> Bool ) : (Trie2D, ?V) { switch (find(t, k1, k1_eq)) { case null { (t, null) }; case (?inner) { let (updated_inner, ov) = remove(inner, k2, k2_eq); let (updated_outer, _) = put(t, k1, k1_eq, updated_inner); - (updated_outer, ov); - }; - }; + (updated_outer, ov) + } + } }; /// Remove the given key-key pair's value in the 3D trie; return the @@ -1174,16 +1174,16 @@ module { k2 : Key, k2_eq : (K2, K2) -> Bool, k3 : Key, - k3_eq : (K3, K3) -> Bool, + k3_eq : (K3, K3) -> Bool ) : (Trie3D, ?V) { switch (find(t, k1, k1_eq)) { case null { (t, null) }; case (?inner) { let (updated_inner, ov) = remove2D(inner, k2, k2_eq, k3, k3_eq); let (updated_outer, _) = put(t, k1, k1_eq, updated_inner); - (updated_outer, ov); - }; - }; + (updated_outer, ov) + } + } }; /// Like [`mergeDisjoint`](#mergedisjoint), except instead of merging a @@ -1192,16 +1192,16 @@ module { public func mergeDisjoint2D( t : Trie2D, k1_eq : (K1, K1) -> Bool, - k2_eq : (K2, K2) -> Bool, + k2_eq : (K2, K2) -> Bool ) : Trie { foldUp( t, func(t1 : Trie, t2 : Trie) : Trie { - mergeDisjoint(t1, t2, k2_eq); + mergeDisjoint(t1, t2, k2_eq) }, func(_ : K1, t : Trie) : Trie { t }, - #empty, - ); + #empty + ) }; -}; +} diff --git a/src/TrieMap.mo b/src/TrieMap.mo index 40ed3af7..de002a26 100644 --- a/src/TrieMap.mo +++ b/src/TrieMap.mo @@ -40,15 +40,15 @@ module { map := map2; switch (ov) { case null { _size += 1 }; - case _ {}; + case _ {} }; - ov; + ov }; /// Get the (optional) value associated with the given key. public func get(k : K) : ?V { let keyObj = { key = k; hash = hashOf(k) }; - T.find(map, keyObj, isEq); + T.find(map, keyObj, isEq) }; /// Delete the (optional) value associated with the given key. @@ -61,23 +61,23 @@ module { map := t; switch (ov) { case null {}; - case (?_) { _size -= 1 }; + case (?_) { _size -= 1 } }; - ov; + ov }; /// An `Iter` over the keys. /// /// Each iterator gets a _persistent view_ of the mapping, independent of concurrent updates to the iterated map. public func keys() : I.Iter { - I.map(entries(), func(kv : (K, V)) : K { kv.0 }); + I.map(entries(), func(kv : (K, V)) : K { kv.0 }) }; /// An `Iter` over the values. /// /// Each iterator gets a _persistent view_ of the mapping, independent of concurrent updates to the iterated map. public func vals() : I.Iter { - I.map(entries(), func(kv : (K, V)) : V { kv.1 }); + I.map(entries(), func(kv : (K, V)) : V { kv.1 }) }; /// Returns an `Iter` over the entries. @@ -93,52 +93,52 @@ module { switch trie { case (#empty) { stack := stack2; - next(); + next() }; case (#leaf({ keyvals = null })) { stack := stack2; - next(); + next() }; case (#leaf({ size = c; keyvals = ?((k, v), kvs) })) { stack := ?(#leaf({ size = c -1; keyvals = kvs }), stack2); - ?(k.key, v); + ?(k.key, v) }; case (#branch(br)) { stack := ?(br.left, ?(br.right, stack2)); - next(); - }; - }; - }; - }; - }; - }; - }; + next() + } + } + } + } + } + } + } }; /// Clone the map, given its key operations. public func clone( h : TrieMap, keyEq : (K, K) -> Bool, - keyHash : K -> Hash.Hash, + keyHash : K -> Hash.Hash ) : TrieMap { let h2 = TrieMap(keyEq, keyHash); for ((k, v) in h.entries()) { - h2.put(k, v); + h2.put(k, v) }; - h2; + h2 }; /// Clone an iterator of key-value pairs. public func fromEntries( entries : I.Iter<(K, V)>, keyEq : (K, K) -> Bool, - keyHash : K -> Hash.Hash, + keyHash : K -> Hash.Hash ) : TrieMap { let h = TrieMap(keyEq, keyHash); for ((k, v) in entries) { - h.put(k, v); + h.put(k, v) }; - h; + h }; /// Transform (map) the values of a map, retaining its keys. @@ -146,14 +146,14 @@ module { h : TrieMap, keyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash, - mapFn : (K, V1) -> V2, + mapFn : (K, V1) -> V2 ) : TrieMap { let h2 = TrieMap(keyEq, keyHash); for ((k, v1) in h.entries()) { let v2 = mapFn(k, v1); - h2.put(k, v2); + h2.put(k, v2) }; - h2; + h2 }; /// Transform and filter the values of a map, retaining its keys. @@ -161,18 +161,18 @@ module { h : TrieMap, keyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash, - mapFn : (K, V1) -> ?V2, + mapFn : (K, V1) -> ?V2 ) : TrieMap { let h2 = TrieMap(keyEq, keyHash); for ((k, v1) in h.entries()) { switch (mapFn(k, v1)) { case null {}; case (?v2) { - h2.put(k, v2); - }; - }; + h2.put(k, v2) + } + } }; - h2; + h2 }; -}; +} diff --git a/src/TrieSet.mo b/src/TrieSet.mo index 7ce2f2cb..f423d76c 100644 --- a/src/TrieSet.mo +++ b/src/TrieSet.mo @@ -27,20 +27,20 @@ module { /// Put an element into the set. public func put(s : Set, x : T, xh : Hash, eq : (T, T) -> Bool) : Set { let (s2, _) = Trie.put(s, { key = x; hash = xh }, eq, ()); - s2; + s2 }; /// Delete an element from the set. public func delete(s : Set, x : T, xh : Hash, eq : (T, T) -> Bool) : Set { let (s2, _) = Trie.remove(s, { key = x; hash = xh }, eq); - s2; + s2 }; /// Test if two sets are equal. public func equal(s1 : Set, s2 : Set, eq : (T, T) -> Bool) : Bool { // XXX: Todo: use a smarter check func unitEqual(_ : (), _ : ()) : Bool { true }; - Trie.equalStructure(s1, s2, eq, unitEqual); + Trie.equalStructure(s1, s2, eq, unitEqual) }; /// The number of set elements, set's cardinality. @@ -49,49 +49,49 @@ module { s, func(n : Nat, m : Nat) : Nat { n + m }, func(_ : T, _ : ()) : Nat { 1 }, - 0, - ); + 0 + ) }; /// Test if a set contains a given element. public func mem(s : Set, x : T, xh : Hash, eq : (T, T) -> Bool) : Bool { switch (Trie.find(s, { key = x; hash = xh }, eq)) { case null { false }; - case (?_) { true }; - }; + case (?_) { true } + } }; /// [Set union](https://en.wikipedia.org/wiki/Union_(set_theory)). public func union(s1 : Set, s2 : Set, eq : (T, T) -> Bool) : Set { let s3 = Trie.merge(s1, s2, eq); - s3; + s3 }; /// [Set difference](https://en.wikipedia.org/wiki/Difference_(set_theory)). public func diff(s1 : Set, s2 : Set, eq : (T, T) -> Bool) : Set { let s3 = Trie.diff(s1, s2, eq); - s3; + s3 }; /// [Set intersection](https://en.wikipedia.org/wiki/Intersection_(set_theory)). public func intersect(s1 : Set, s2 : Set, eq : (T, T) -> Bool) : Set { let noop : ((), ()) -> (()) = func(_ : (), _ : ()) : (()) = (); let s3 = Trie.join(s1, s2, eq, noop); - s3; + s3 }; //// Construct a set from an array. public func fromArray(arr : [T], elemHash : T -> Hash, eq : (T, T) -> Bool) : Set { var s = empty(); for (elem in arr.vals()) { - s := put(s, elem, elemHash(elem), eq); + s := put(s, elem, elemHash(elem), eq) }; - s; + s }; //// Returns the set as an array. public func toArray(s : Set) : [T] { - Trie.toArray(s, func(t : T, _ : ()) : T { t }); + Trie.toArray(s, func(t : T, _ : ()) : T { t }) } -}; +} diff --git a/test/RBTreeTest.mo b/test/RBTreeTest.mo index 3ddda7c0..b18c3567 100644 --- a/test/RBTreeTest.mo +++ b/test/RBTreeTest.mo @@ -13,7 +13,7 @@ let sorted = [ (6, "loyalist"), (7, "enthusiast"), (8, "challenger"), - (9, "peacemaker"), + (9, "peacemaker") ]; let unsort = [ @@ -25,7 +25,7 @@ let unsort = [ (2, "helper"), (8, "challenger"), (5, "investigator"), - (7, "enthusiast"), + (7, "enthusiast") ]; var t = RBT.RBTree(Nat.compare); @@ -35,15 +35,15 @@ assert RBT.size(t.share()) == 0; for ((num, lab) in unsort.vals()) { Debug.print(Nat.toText num); Debug.print lab; - t.put(num, lab); + t.put(num, lab) }; do { var i = 1; for ((num, lab) in t.entries()) { assert (num == i); - i += 1; - }; + i += 1 + } }; assert RBT.size(t.share()) == 9; @@ -52,12 +52,12 @@ do { var i = 9; for ((num, lab) in t.entriesRev()) { assert (num == i); - i -= 1; - }; + i -= 1 + } }; assert RBT.size(t.share()) == 9; t.delete(5); -assert RBT.size(t.share()) == 8; +assert RBT.size(t.share()) == 8 diff --git a/test/TrieExampleTest.mo b/test/TrieExampleTest.mo index 2b47a2e3..d788b615 100644 --- a/test/TrieExampleTest.mo +++ b/test/TrieExampleTest.mo @@ -20,12 +20,12 @@ debug { var found = false; label here : () { for (y in b.vals()) { - if (eq(x, y)) { found := true; break here }; - }; + if (eq(x, y)) { found := true; break here } + } }; - if (not found) { return false }; + if (not found) { return false } }; - return true; + return true }; // note that `put("hello", ..., 0)` happens "after" t2, but map is immutable (applicative). @@ -34,5 +34,5 @@ debug { func equalKV(a : (Text, Nat), b : (Text, Nat)) : Bool { a == b }; assert (isSubSet(actual, expected, equalKV)); assert (isSubSet(expected, actual, equalKV)); - assert Trie.isValid(t2, false); -}; + assert Trie.isValid(t2, false) +} diff --git a/test/arrayTest.mo b/test/arrayTest.mo index 4738b444..867b3eaa 100644 --- a/test/arrayTest.mo +++ b/test/arrayTest.mo @@ -13,376 +13,376 @@ let suite = Suite.suite( Suite.test( "init", Array.freeze(Array.init(3, 4)), - M.equals(T.array(T.intTestable, [4, 4, 4])), + M.equals(T.array(T.intTestable, [4, 4, 4])) ), Suite.test( "init empty", Array.freeze(Array.init(0, 4)), - M.equals(T.array(T.intTestable, [])), + M.equals(T.array(T.intTestable, [])) ), Suite.test( "tabulate", Array.tabulate(3, func(i : Nat) = i * 2), - M.equals(T.array(T.intTestable, [0, 2, 4])), + M.equals(T.array(T.intTestable, [0, 2, 4])) ), Suite.test( "tabulate empty", Array.tabulate(0, func(i : Nat) = i), - M.equals(T.array(T.intTestable, [])), + M.equals(T.array(T.intTestable, [])) ), Suite.test( "tabulateVar", Array.freeze(Array.tabulateVar(3, func(i : Nat) = i * 2)), - M.equals(T.array(T.intTestable, [0, 2, 4])), + M.equals(T.array(T.intTestable, [0, 2, 4])) ), Suite.test( "tabulateVar empty", Array.freeze(Array.tabulateVar(0, func(i : Nat) = i)), - M.equals(T.array(T.intTestable, [])), + M.equals(T.array(T.intTestable, [])) ), Suite.test( "freeze", Array.freeze([var 1, 2, 3]), - M.equals(T.array(T.intTestable, [1, 2, 3])), + M.equals(T.array(T.intTestable, [1, 2, 3])) ), Suite.test( "freeze empty", Array.freeze([var]), - M.equals(T.array(T.intTestable, [])), + M.equals(T.array(T.intTestable, [])) ), Suite.test( "thaw round trip", Array.freeze(Array.thaw([1, 2, 3])), - M.equals(T.array(T.intTestable, [1, 2, 3])), + M.equals(T.array(T.intTestable, [1, 2, 3])) ), Suite.test( "thaw round trip empty", Array.freeze(Array.thaw([])), - M.equals(T.array(T.intTestable, [])), + M.equals(T.array(T.intTestable, [])) ), Suite.test( "equal", Array.equal([1, 2, 3], [1, 2, 3], Int.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), Suite.test( "equal empty", Array.equal([], [], Int.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), Suite.test( "not equal one empty", Array.equal([], [2, 3], Int.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), Suite.test( "not equal different lengths", Array.equal([1, 2, 3], [2, 4], Int.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), Suite.test( "not equal same lengths", Array.equal([1, 2, 3], [1, 2, 4], Int.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), Suite.test( "find", Array.find([1, 9, 4, 8], func x = x == 9), - M.equals(T.optional(T.natTestable, ?9)), + M.equals(T.optional(T.natTestable, ?9)) ), Suite.test( "find fail", Array.find([1, 9, 4, 8], func _ = false), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), Suite.test( "find empty", Array.find([], func _ = true), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), Suite.test( "append", Array.append([1, 2, 3], [4, 5, 6]), - M.equals(T.array(T.intTestable, [1, 2, 3, 4, 5, 6])), + M.equals(T.array(T.intTestable, [1, 2, 3, 4, 5, 6])) ), Suite.test( "append first empty", Array.append([], [4, 5, 6]), - M.equals(T.array(T.intTestable, [4, 5, 6])), + M.equals(T.array(T.intTestable, [4, 5, 6])) ), Suite.test( "append second empty", Array.append([1, 2, 3], []), - M.equals(T.array(T.intTestable, [1, 2, 3])), + M.equals(T.array(T.intTestable, [1, 2, 3])) ), Suite.test( "append both empty", Array.append([], []), - M.equals(T.array(T.intTestable, [])), + M.equals(T.array(T.intTestable, [])) ), Suite.test( "sort", Array.sort([2, 3, 1], Nat.compare), - M.equals(T.array(T.natTestable, [1, 2, 3])), + M.equals(T.array(T.natTestable, [1, 2, 3])) ), Suite.test( "sort empty array", Array.sort([], Nat.compare), - M.equals(T.array(T.natTestable, [])), + M.equals(T.array(T.natTestable, [])) ), Suite.test( "sort already sorted", Array.sort([1, 2, 3, 4, 5], Nat.compare), - M.equals(T.array(T.natTestable, [1, 2, 3, 4, 5])), + M.equals(T.array(T.natTestable, [1, 2, 3, 4, 5])) ), Suite.test( "sort repeated elements", Array.sort([2, 2, 2, 2, 2], Nat.compare), - M.equals(T.array(T.natTestable, [2, 2, 2, 2, 2])), + M.equals(T.array(T.natTestable, [2, 2, 2, 2, 2])) ), Suite.test( "sortInPlace", do { let array = [var 2, 3, 1]; Array.sortInPlace(array, Nat.compare); - Array.freeze(array); + Array.freeze(array) }, - M.equals(T.array(T.natTestable, [1, 2, 3])), + M.equals(T.array(T.natTestable, [1, 2, 3])) ), Suite.test( "sortInPlace empty", do { let array = [var]; Array.sortInPlace(array, Nat.compare); - Array.freeze(array); + Array.freeze(array) }, - M.equals(T.array(T.natTestable, [])), + M.equals(T.array(T.natTestable, [])) ), Suite.test( "sortInPlace already sorted", do { let array = [var 1, 2, 3, 4, 5]; Array.sortInPlace(array, Nat.compare); - Array.freeze(array); + Array.freeze(array) }, - M.equals(T.array(T.natTestable, [1, 2, 3, 4, 5])), + M.equals(T.array(T.natTestable, [1, 2, 3, 4, 5])) ), Suite.test( "sortInPlace repeated elements", do { let array = [var 2, 2, 2, 2, 2]; Array.sortInPlace(array, Nat.compare); - Array.freeze(array); + Array.freeze(array) }, - M.equals(T.array(T.natTestable, [2, 2, 2, 2, 2])), + M.equals(T.array(T.natTestable, [2, 2, 2, 2, 2])) ), Suite.test( "reverse", Array.reverse([0, 1, 2, 2, 3]), - M.equals(T.array(T.natTestable, [3, 2, 2, 1, 0])), + M.equals(T.array(T.natTestable, [3, 2, 2, 1, 0])) ), Suite.test( "reverse empty", Array.reverse([]), - M.equals(T.array(T.natTestable, [])), + M.equals(T.array(T.natTestable, [])) ), Suite.test( "reverse singleton", Array.reverse([0]), - M.equals(T.array(T.natTestable, [0])), + M.equals(T.array(T.natTestable, [0])) ), Suite.test( "map", Array.map([1, 2, 3], func x = x % 2 == 0), - M.equals(T.array(T.boolTestable, [false, true, false])), + M.equals(T.array(T.boolTestable, [false, true, false])) ), Suite.test( "map empty", Array.map([], func x = x % 2 == 0), - M.equals(T.array(T.boolTestable, [])), + M.equals(T.array(T.boolTestable, [])) ), Suite.test( "filter", Array.filter([1, 2, 3, 4, 5, 6], func x = x % 2 == 0), - M.equals(T.array(T.natTestable, [2, 4, 6])), + M.equals(T.array(T.natTestable, [2, 4, 6])) ), Suite.test( "filter empty", Array.filter([], func x = x % 2 == 0), - M.equals(T.array(T.natTestable, [])), + M.equals(T.array(T.natTestable, [])) ), Suite.test( "mapEntries", Array.mapEntries([1, 2, 3], func(x, i) = x + i), - M.equals(T.array(T.natTestable, [1, 3, 5])), + M.equals(T.array(T.natTestable, [1, 3, 5])) ), Suite.test( "mapEntries empty", Array.mapEntries([], func(x, i) = x + i), - M.equals(T.array(T.natTestable, [])), + M.equals(T.array(T.natTestable, [])) ), Suite.test( "mapFilter", Array.mapFilter([1, 2, 3, 4, 5, 6], func x { if (x % 2 == 0) ?x else null }), - M.equals(T.array(T.natTestable, [2, 4, 6])), + M.equals(T.array(T.natTestable, [2, 4, 6])) ), Suite.test( "mapFilter keep all", Array.mapFilter([1, 2, 3], func x = ?x), - M.equals(T.array(T.natTestable, [1, 2, 3])), + M.equals(T.array(T.natTestable, [1, 2, 3])) ), Suite.test( "mapFilter keep none", Array.mapFilter([1, 2, 3], func _ = null), - M.equals(T.array(T.natTestable, [])), + M.equals(T.array(T.natTestable, [])) ), Suite.test( "mapFilter empty", Array.mapFilter([], func x { if (x % 2 == 0) ?x else null }), - M.equals(T.array(T.natTestable, [])), + M.equals(T.array(T.natTestable, [])) ), Suite.test( "mapResult", Array.mapResult( [1, 2, 3], - func x { if (x >= 0) { #ok(Int.abs x) } else { #err "error message" } }, + func x { if (x >= 0) { #ok(Int.abs x) } else { #err "error message" } } ), - M.equals(T.result<[Nat], Text>(T.arrayTestable(T.natTestable), T.textTestable, #ok([1, 2, 3]))), + M.equals(T.result<[Nat], Text>(T.arrayTestable(T.natTestable), T.textTestable, #ok([1, 2, 3]))) ), Suite.test( "mapResult fail first", Array.mapResult( [-1, 2, 3], - func x { if (x >= 0) { #ok(Int.abs x) } else { #err "error message" } }, + func x { if (x >= 0) { #ok(Int.abs x) } else { #err "error message" } } ), - M.equals(T.result<[Nat], Text>(T.arrayTestable(T.natTestable), T.textTestable, #err "error message")), + M.equals(T.result<[Nat], Text>(T.arrayTestable(T.natTestable), T.textTestable, #err "error message")) ), Suite.test( "mapResult fail last", Array.mapResult( [1, 2, -3], - func x { if (x >= 0) { #ok(Int.abs x) } else { #err "error message" } }, + func x { if (x >= 0) { #ok(Int.abs x) } else { #err "error message" } } ), - M.equals(T.result<[Nat], Text>(T.arrayTestable(T.natTestable), T.textTestable, #err "error message")), + M.equals(T.result<[Nat], Text>(T.arrayTestable(T.natTestable), T.textTestable, #err "error message")) ), Suite.test( "mapResult empty", Array.mapResult( [], - func x = #ok x, + func x = #ok x ), - M.equals(T.result<[Nat], Text>(T.arrayTestable(T.natTestable), T.textTestable, #ok([]))), + M.equals(T.result<[Nat], Text>(T.arrayTestable(T.natTestable), T.textTestable, #ok([]))) ), Suite.test( "chain", Array.chain([0, 1, 2], func x = [x, -x]), - M.equals(T.array(T.intTestable, [0, 0, 1, -1, 2, -2])), + M.equals(T.array(T.intTestable, [0, 0, 1, -1, 2, -2])) ), Suite.test( "chain empty", Array.chain([], func x = [x, -x]), - M.equals(T.array(T.intTestable, [])), + M.equals(T.array(T.intTestable, [])) ), Suite.test( "foldLeft", Array.foldLeft(["a", "b", "c"], "", Text.concat), - M.equals(T.text("abc")), + M.equals(T.text("abc")) ), Suite.test( "foldLeft empty", Array.foldLeft([], "base", Text.concat), - M.equals(T.text("base")), + M.equals(T.text("base")) ), Suite.test( "foldRight", Array.foldRight(["a", "b", "c"], "", func(x, acc) = acc # x), - M.equals(T.text("cba")), + M.equals(T.text("cba")) ), Suite.test( "foldRight empty", Array.foldRight([], "base", Text.concat), - M.equals(T.text("base")), + M.equals(T.text("base")) ), Suite.test( "flatten", Array.flatten([[1, 2, 3], [], [1]]), - M.equals(T.array(T.intTestable, [1, 2, 3, 1])), + M.equals(T.array(T.intTestable, [1, 2, 3, 1])) ), Suite.test( "flatten empty start", Array.flatten([[], [1, 2, 3], [], [1]]), - M.equals(T.array(T.intTestable, [1, 2, 3, 1])), + M.equals(T.array(T.intTestable, [1, 2, 3, 1])) ), Suite.test( "flatten empty end", Array.flatten([[1, 2, 3], [], [1], []]), - M.equals(T.array(T.intTestable, [1, 2, 3, 1])), + M.equals(T.array(T.intTestable, [1, 2, 3, 1])) ), Suite.test( "flatten singleton", Array.flatten([[1, 2, 3]]), - M.equals(T.array(T.intTestable, [1, 2, 3])), + M.equals(T.array(T.intTestable, [1, 2, 3])) ), Suite.test( "flatten empty", Array.flatten([[]]), - M.equals(T.array(T.intTestable, [])), + M.equals(T.array(T.intTestable, [])) ), Suite.test( "flatten empty", Array.flatten([]), - M.equals(T.array(T.intTestable, [])), + M.equals(T.array(T.intTestable, [])) ), Suite.test( "make", Array.make(0), - M.equals(T.array(T.intTestable, [0])), + M.equals(T.array(T.intTestable, [0])) ), Suite.test( "vals", do { var sum = 0; for (x in Array.vals([1, 2, 3])) { - sum += x; + sum += x }; - sum; + sum }, - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), Suite.test( "vals empty", do { var sum = 0; for (x in Array.vals([])) { - sum += x; + sum += x }; - sum; + sum }, - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), Suite.test( "keys", do { var sum = 0; for (x in Array.keys([1, 2, 3])) { - sum += x; + sum += x }; - sum; + sum }, - M.equals(T.nat(3)), + M.equals(T.nat(3)) ), Suite.test( "keys empty", do { var sum = 0; for (x in Array.keys([])) { - sum += x; + sum += x }; - sum; + sum }, - M.equals(T.nat(0)), - ), - ], + M.equals(T.nat(0)) + ) + ] ); -Suite.run(suite); +Suite.run(suite) diff --git a/test/bufTest.mo b/test/bufTest.mo index 513c0e9f..89b9bce7 100644 --- a/test/bufTest.mo +++ b/test/bufTest.mo @@ -15,11 +15,11 @@ let { run; test; suite } = Suite; let NatBufferTestable : T.Testable> = object { public func display(buffer : B.Buffer) : Text { - B.toText(buffer, Nat.toText); + B.toText(buffer, Nat.toText) }; public func equals(buffer1 : B.Buffer, buffer2 : B.Buffer) : Bool { - B.equal(buffer1, buffer2, Nat.equal); - }; + B.equal(buffer1, buffer2, Nat.equal) + } }; class OrderTestable(initItem : Order.Order) : T.TestableItem { @@ -27,17 +27,17 @@ class OrderTestable(initItem : Order.Order) : T.TestableItem { public func display(order : Order.Order) : Text { switch (order) { case (#less) { - "#less"; + "#less" }; case (#greater) { - "#greater"; + "#greater" }; case (#equal) { - "#equal"; - }; - }; + "#equal" + } + } }; - public let equals = Order.equal; + public let equals = Order.equal }; /* --------------------------------------- */ @@ -48,22 +48,22 @@ run( test( "initial size", B.Buffer(10).size(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "initial capacity", B.Buffer(10).capacity(), - M.equals(T.nat(10)), - ), - ], - ), + M.equals(T.nat(10)) + ) + ] + ) ); /* --------------------------------------- */ var buffer = B.Buffer(10); for (i in Iter.range(0, 3)) { - buffer.add(i); + buffer.add(i) }; run( @@ -73,26 +73,26 @@ run( test( "size", buffer.size(), - M.equals(T.nat(4)), + M.equals(T.nat(4)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(10)), + M.equals(T.nat(10)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(2); for (i in Iter.range(0, 3)) { - buffer.add(i); + buffer.add(i) }; run( @@ -102,26 +102,26 @@ run( test( "size", buffer.size(), - M.equals(T.nat(4)), + M.equals(T.nat(4)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(0); for (i in Iter.range(0, 3)) { - buffer.add(i); + buffer.add(i) }; run( @@ -131,20 +131,20 @@ run( test( "size", buffer.size(), - M.equals(T.nat(4)), + M.equals(T.nat(4)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3])) + ) + ] + ) ); /* --------------------------------------- */ @@ -157,31 +157,31 @@ run( test( "return value", buffer.removeLast(), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), test( "size", buffer.size(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(2)), + M.equals(T.nat(2)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [])), - ), - ], - ), + M.equals(T.array(T.natTestable, [])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(2); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; run( @@ -191,35 +191,35 @@ run( test( "return value", buffer.removeLast(), - M.equals(T.optional(T.natTestable, ?5)), + M.equals(T.optional(T.natTestable, ?5)) ), test( "size", buffer.size(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; for (i in Iter.range(0, 5)) { - ignore buffer.removeLast(); + ignore buffer.removeLast() }; run( @@ -229,31 +229,31 @@ run( test( "return value", buffer.removeLast(), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), test( "size", buffer.size(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(2)), + M.equals(T.nat(2)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [])), - ), - ], - ), + M.equals(T.array(T.natTestable, [])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(0); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; run( @@ -263,51 +263,51 @@ run( test( "return value", buffer.remove(2), - M.equals(T.nat(2)), + M.equals(T.nat(2)) ), test( "size", buffer.size(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 3, 4, 5])), + M.equals(T.array(T.natTestable, [0, 1, 3, 4, 5])) ), test( "return value", buffer.remove(0), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "size", buffer.size(), - M.equals(T.nat(4)), + M.equals(T.nat(4)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [1, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [1, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 2)) { - buffer.add(i); + buffer.add(i) }; run( @@ -317,35 +317,35 @@ run( test( "return value", buffer.remove(2), - M.equals(T.nat(2)), + M.equals(T.nat(2)) ), test( "size", buffer.size(), - M.equals(T.nat(2)), + M.equals(T.nat(2)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(3)), + M.equals(T.nat(3)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(0); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; for (i in Iter.range(0, 5)) { - ignore buffer.remove(5 - i); + ignore buffer.remove(5 - i) }; run( @@ -355,26 +355,26 @@ run( test( "size", buffer.size(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(2)), + M.equals(T.nat(2)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [])), - ), - ], - ), + M.equals(T.array(T.natTestable, [])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(1); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer.filterEntries(func(_, x) = x % 2 == 0); @@ -386,20 +386,20 @@ run( test( "size", buffer.size(), - M.equals(T.nat(3)), + M.equals(T.nat(3)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 2, 4])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 2, 4])) + ) + ] + ) ); /* --------------------------------------- */ @@ -413,26 +413,26 @@ run( test( "size", buffer.size(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [])), - ), - ], - ), + M.equals(T.array(T.natTestable, [])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(12); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer.filterEntries(func(i, x) = i + x == 2); @@ -443,26 +443,26 @@ run( test( "size", buffer.size(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [1])), - ), - ], - ), + M.equals(T.array(T.natTestable, [1])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(5); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer.filterEntries(func(_, _) = false); @@ -473,26 +473,26 @@ run( test( "size", buffer.size(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(2)), + M.equals(T.nat(2)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(10); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; run( @@ -502,26 +502,26 @@ run( test( "get", buffer.get(2), - M.equals(T.nat(2)), + M.equals(T.nat(2)) ), test( "getOpt success", buffer.getOpt(0), - M.equals(T.optional(T.natTestable, ?0)), + M.equals(T.optional(T.natTestable, ?0)) ), test( "getOpt out of bounds", buffer.getOpt(10), - M.equals(T.optional(T.natTestable, null : ?Nat)), - ), - ], - ), + M.equals(T.optional(T.natTestable, null : ?Nat)) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(10); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer.put(2, 20); @@ -533,21 +533,21 @@ run( test( "size", buffer.size(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 20, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 20, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(10); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer.reserve(6); @@ -559,26 +559,26 @@ run( test( "size", buffer.size(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(10); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer.reserve(20); @@ -590,32 +590,32 @@ run( test( "size", buffer.size(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(20)), + M.equals(T.nat(20)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(10); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; var buffer2 = B.Buffer(20); for (i in Iter.range(10, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer.append(buffer2); @@ -627,26 +627,26 @@ run( test( "size", buffer.size(), - M.equals(T.nat(12)), + M.equals(T.nat(12)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(18)), + M.equals(T.nat(18)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(10); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.Buffer(0); @@ -660,20 +660,20 @@ run( test( "size", buffer.size(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(10)), + M.equals(T.nat(10)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ @@ -682,7 +682,7 @@ buffer := B.Buffer(10); buffer2 := B.Buffer(10); for (i in Iter.range(0, 5)) { - buffer2.add(i); + buffer2.add(i) }; buffer.append(buffer2); @@ -694,27 +694,27 @@ run( test( "size", buffer.size(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(10)), + M.equals(T.nat(10)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(8); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer.insert(3, 30); @@ -726,27 +726,27 @@ run( test( "size", buffer.size(), - M.equals(T.nat(7)), + M.equals(T.nat(7)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 30, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 30, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(8); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer.insert(6, 60); @@ -758,27 +758,27 @@ run( test( "size", buffer.size(), - M.equals(T.nat(7)), + M.equals(T.nat(7)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 60])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 60])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(8); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer.insert(0, 10); @@ -790,27 +790,27 @@ run( test( "size", buffer.size(), - M.equals(T.nat(7)), + M.equals(T.nat(7)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [10, 0, 1, 2, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [10, 0, 1, 2, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(6); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer.insert(3, 30); @@ -822,20 +822,20 @@ run( test( "size", buffer.size(), - M.equals(T.nat(7)), + M.equals(T.nat(7)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(9)), + M.equals(T.nat(9)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 30, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 30, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ @@ -850,20 +850,20 @@ run( test( "size", buffer.size(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0])) + ) + ] + ) ); /* --------------------------------------- */ @@ -878,33 +878,33 @@ run( test( "size", buffer.size(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(15); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.Buffer(10); for (i in Iter.range(10, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer.insertBuffer(3, buffer2); @@ -916,33 +916,33 @@ run( test( "size", buffer.size(), - M.equals(T.nat(12)), + M.equals(T.nat(12)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(15)), + M.equals(T.nat(15)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 10, 11, 12, 13, 14, 15, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 10, 11, 12, 13, 14, 15, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(15); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.Buffer(10); for (i in Iter.range(10, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer.insertBuffer(0, buffer2); @@ -954,33 +954,33 @@ run( test( "size", buffer.size(), - M.equals(T.nat(12)), + M.equals(T.nat(12)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(15)), + M.equals(T.nat(15)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(15); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.Buffer(10); for (i in Iter.range(10, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer.insertBuffer(6, buffer2); @@ -992,33 +992,33 @@ run( test( "size", buffer.size(), - M.equals(T.nat(12)), + M.equals(T.nat(12)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(15)), + M.equals(T.nat(15)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(8); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.Buffer(10); for (i in Iter.range(10, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer.insertBuffer(3, buffer2); @@ -1030,33 +1030,33 @@ run( test( "size", buffer.size(), - M.equals(T.nat(12)), + M.equals(T.nat(12)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(18)), + M.equals(T.nat(18)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 10, 11, 12, 13, 14, 15, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 10, 11, 12, 13, 14, 15, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(8); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.Buffer(10); for (i in Iter.range(10, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer.insertBuffer(0, buffer2); @@ -1068,33 +1068,33 @@ run( test( "size", buffer.size(), - M.equals(T.nat(12)), + M.equals(T.nat(12)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(18)), + M.equals(T.nat(18)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(8); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.Buffer(10); for (i in Iter.range(10, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer.insertBuffer(6, buffer2); @@ -1106,20 +1106,20 @@ run( test( "size", buffer.size(), - M.equals(T.nat(12)), + M.equals(T.nat(12)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(18)), + M.equals(T.nat(18)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15])) + ) + ] + ) ); /* --------------------------------------- */ @@ -1128,7 +1128,7 @@ buffer := B.Buffer(7); buffer2 := B.Buffer(10); for (i in Iter.range(10, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer.insertBuffer(0, buffer2); @@ -1140,20 +1140,20 @@ run( test( "size", buffer.size(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(7)), + M.equals(T.nat(7)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [10, 11, 12, 13, 14, 15])), - ), - ], - ), + M.equals(T.array(T.natTestable, [10, 11, 12, 13, 14, 15])) + ) + ] + ) ); /* --------------------------------------- */ @@ -1162,7 +1162,7 @@ buffer := B.Buffer(3); buffer2 := B.Buffer(10); for (i in Iter.range(10, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer.insertBuffer(0, buffer2); @@ -1174,27 +1174,27 @@ run( test( "size", buffer.size(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(9)), + M.equals(T.nat(9)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [10, 11, 12, 13, 14, 15])), - ), - ], - ), + M.equals(T.array(T.natTestable, [10, 11, 12, 13, 14, 15])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; buffer.clear(); @@ -1206,27 +1206,27 @@ run( test( "size", buffer.size(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [])), - ), - ], - ), + M.equals(T.array(T.natTestable, [])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.clone(buffer); @@ -1238,34 +1238,34 @@ run( test( "size", buffer2.size(), - M.equals(T.nat(buffer.size())), + M.equals(T.nat(buffer.size())) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(buffer2.capacity())), + M.equals(T.nat(buffer2.capacity())) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, B.toArray(buffer2))), - ), - ], - ), + M.equals(T.array(T.natTestable, B.toArray(buffer2))) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; var size = 0; for (element in buffer.vals()) { M.assertThat(element, M.equals(T.nat(size))); - size += 1; + size += 1 }; run( @@ -1275,10 +1275,10 @@ run( test( "size", size, - M.equals(T.nat(7)), - ), - ], - ), + M.equals(T.nat(7)) + ) + ] + ) ); /* --------------------------------------- */ @@ -1289,15 +1289,15 @@ run( test( "fromArray and toArray", B.toArray(B.fromArray([0, 1, 2, 3])), - M.equals(T.array(T.natTestable, [0, 1, 2, 3])), + M.equals(T.array(T.natTestable, [0, 1, 2, 3])) ), test( "fromVarArray", B.toArray(B.fromVarArray([var 0, 1, 2, 3])), - M.equals(T.array(T.natTestable, [0, 1, 2, 3])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3])) + ) + ] + ) ); /* --------------------------------------- */ @@ -1308,22 +1308,22 @@ run( test( "fromArray and toArray", B.toArray(B.fromArray([])), - M.equals(T.array(T.natTestable, [])), + M.equals(T.array(T.natTestable, [])) ), test( "fromVarArray", B.toArray(B.fromVarArray([var])), - M.equals(T.array(T.natTestable, [])), - ), - ], - ), + M.equals(T.array(T.natTestable, [])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; run( @@ -1333,22 +1333,22 @@ run( test( "fromIter and vals", B.toArray(B.fromIter(buffer.vals())), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 6])), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 6])) ), test( "empty", B.toArray(B.fromIter(B.Buffer(2).vals())), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; B.trimToSize(buffer); @@ -1360,15 +1360,15 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(7)), + M.equals(T.nat(7)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 6])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 6])) + ) + ] + ) ); /* --------------------------------------- */ @@ -1383,22 +1383,22 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [])), - ), - ], - ), + M.equals(T.array(T.natTestable, [])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.map(buffer, func x = x * 2); @@ -1410,15 +1410,15 @@ run( test( "capacity", buffer2.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer2), - M.equals(T.array(T.natTestable, [0, 2, 4, 6, 8, 10, 12])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 2, 4, 6, 8, 10, 12])) + ) + ] + ) ); /* --------------------------------------- */ @@ -1433,22 +1433,22 @@ run( test( "capacity", buffer2.capacity(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "elements", B.toArray(buffer2), - M.equals(T.array(T.natTestable, [])), - ), - ], - ), + M.equals(T.array(T.natTestable, [])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; var sum = 0; @@ -1462,27 +1462,27 @@ run( test( "sum", sum, - M.equals(T.nat(21)), + M.equals(T.nat(21)) ), test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 6])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5, 6])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.chain(buffer, func x = B.make x); @@ -1494,17 +1494,17 @@ run( test( "elements", B.toArray(buffer2), - M.equals(T.array(T.natTestable, B.toArray(buffer))), - ), - ], - ), + M.equals(T.array(T.natTestable, B.toArray(buffer))) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.mapFilter(buffer, func x = if (x % 2 == 0) { ?x } else { null }); @@ -1516,22 +1516,22 @@ run( test( "capacity", buffer2.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer2), - M.equals(T.array(T.natTestable, [0, 2, 4, 6])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 2, 4, 6])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.mapEntries(buffer, func(i, x) = i * x); @@ -1543,22 +1543,22 @@ run( test( "capacity", buffer2.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer2), - M.equals(T.array(T.natTestable, [0, 1, 4, 9, 16, 25, 36])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 4, 9, 16, 25, 36])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; var bufferResult = B.mapResult(buffer, func x = #ok x); @@ -1570,22 +1570,22 @@ run( test( "return value", #ok buffer, - M.equals(T.result, Text>(NatBufferTestable, T.textTestable, bufferResult)), - ), - ], - ), + M.equals(T.result, Text>(NatBufferTestable, T.textTestable, bufferResult)) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; bufferResult := B.mapResult( buffer, - func x = if (x == 4) { #err "error" } else { #ok x }, + func x = if (x == 4) { #err "error" } else { #ok x } ); run( @@ -1595,17 +1595,17 @@ run( test( "return value", #err "error", - M.equals(T.result, Text>(NatBufferTestable, T.textTestable, bufferResult)), - ), - ], - ), + M.equals(T.result, Text>(NatBufferTestable, T.textTestable, bufferResult)) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; run( @@ -1615,22 +1615,22 @@ run( test( "return value", B.foldLeft(buffer, "", func(acc, x) = acc # Nat.toText(x)), - M.equals(T.text("0123456")), + M.equals(T.text("0123456")) ), test( "return value empty", B.foldLeft(B.Buffer(4), "", func(acc, x) = acc # Nat.toText(x)), - M.equals(T.text("")), - ), - ], - ), + M.equals(T.text("")) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; run( @@ -1640,22 +1640,22 @@ run( test( "return value", B.foldRight(buffer, "", func(x, acc) = acc # Nat.toText(x)), - M.equals(T.text("6543210")), + M.equals(T.text("6543210")) ), test( "return value empty", B.foldRight(B.Buffer(4), "", func(x, acc) = acc # Nat.toText(x)), - M.equals(T.text("")), - ), - ], - ), + M.equals(T.text("")) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; run( @@ -1665,20 +1665,20 @@ run( test( "true", B.forAll(buffer, func x = x >= 0), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "false", B.forAll(buffer, func x = x % 2 == 0), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "default", B.forAll(B.Buffer(2), func _ = false), - M.equals(T.bool(true)), - ), - ], - ), + M.equals(T.bool(true)) + ) + ] + ) ); /* --------------------------------------- */ @@ -1689,20 +1689,20 @@ run( test( "true", B.forSome(buffer, func x = x % 2 == 0), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "false", B.forSome(buffer, func x = x < 0), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "default", B.forSome(B.Buffer(2), func _ = false), - M.equals(T.bool(false)), - ), - ], - ), + M.equals(T.bool(false)) + ) + ] + ) ); /* --------------------------------------- */ @@ -1713,20 +1713,20 @@ run( test( "true", B.forNone(buffer, func x = x < 0), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "false", B.forNone(buffer, func x = x % 2 != 0), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "default", B.forNone(B.Buffer(2), func _ = true), - M.equals(T.bool(true)), - ), - ], - ), + M.equals(T.bool(true)) + ) + ] + ) ); /* --------------------------------------- */ @@ -1740,15 +1740,15 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [1])), - ), - ], - ), + M.equals(T.array(T.natTestable, [1])) + ) + ] + ) ); /* --------------------------------------- */ @@ -1756,7 +1756,7 @@ run( buffer := B.Buffer(3); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; run( @@ -1766,15 +1766,15 @@ run( test( "true", B.contains(buffer, 2, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "true", B.contains(buffer, 9, Nat.equal), - M.equals(T.bool(false)), - ), - ], - ), + M.equals(T.bool(false)) + ) + ] + ) ); /* --------------------------------------- */ @@ -1788,15 +1788,15 @@ run( test( "true", B.contains(buffer, 2, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "true", B.contains(buffer, 9, Nat.equal), - M.equals(T.bool(false)), - ), - ], - ), + M.equals(T.bool(false)) + ) + ] + ) ); /* --------------------------------------- */ @@ -1817,10 +1817,10 @@ run( test( "return value", B.max(buffer, Nat.compare), - M.equals(T.optional(T.natTestable, ?10)), - ), - ], - ), + M.equals(T.optional(T.natTestable, ?10)) + ) + ] + ) ); /* --------------------------------------- */ @@ -1842,10 +1842,10 @@ run( test( "return value", B.min(buffer, Nat.compare), - M.equals(T.optional(T.natTestable, ?0)), - ), - ], - ), + M.equals(T.optional(T.natTestable, ?0)) + ) + ] + ) ); /* --------------------------------------- */ @@ -1860,15 +1860,15 @@ run( test( "true", B.isEmpty(B.Buffer(2)), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "false", B.isEmpty(buffer), - M.equals(T.bool(false)), - ), - ], - ), + M.equals(T.bool(false)) + ) + ] + ) ); /* --------------------------------------- */ @@ -1892,10 +1892,10 @@ run( test( "elements (stable ordering)", B.toArray(buffer), - M.equals(T.array(T.natTestable, [2, 1, 10, 0, 3])), - ), - ], - ), + M.equals(T.array(T.natTestable, [2, 1, 10, 0, 3])) + ) + ] + ) ); /* --------------------------------------- */ @@ -1911,10 +1911,10 @@ run( test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ @@ -1922,7 +1922,7 @@ run( buffer := B.Buffer(3); for (i in Iter.range(0, 4)) { - buffer.add(2); + buffer.add(2) }; B.removeDuplicates(buffer, Nat.compare); @@ -1934,17 +1934,17 @@ run( test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [2])), - ), - ], - ), + M.equals(T.array(T.natTestable, [2])) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; run( @@ -1954,22 +1954,22 @@ run( test( "empty buffer", Nat32.toNat(B.hash(B.Buffer(8), Hash.hash)), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "non-empty buffer", Nat32.toNat(B.hash(buffer, Hash.hash)), - M.equals(T.nat(3365238326)), - ), - ], - ), + M.equals(T.nat(3365238326)) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; run( @@ -1979,33 +1979,33 @@ run( test( "empty buffer", B.toText(B.Buffer(3), Nat.toText), - M.equals(T.text("[]")), + M.equals(T.text("[]")) ), test( "singleton buffer", B.toText(B.make(3), Nat.toText), - M.equals(T.text("[3]")), + M.equals(T.text("[3]")) ), test( "non-empty buffer", B.toText(buffer, Nat.toText), - M.equals(T.text("[0, 1, 2, 3, 4, 5]")), - ), - ], - ), + M.equals(T.text("[0, 1, 2, 3, 4, 5]")) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.Buffer(3); for (i in Iter.range(0, 2)) { - buffer.add(i); + buffer.add(i) }; run( @@ -2015,44 +2015,44 @@ run( test( "empty buffers", B.equal(B.Buffer(3), B.Buffer(2), Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "non-empty buffers", B.equal(buffer, B.clone(buffer), Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "non-empty and empty buffers", B.equal(buffer, B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "non-empty buffers mismatching lengths", B.equal(buffer, buffer2, Nat.equal), - M.equals(T.bool(false)), - ), - ], - ), + M.equals(T.bool(false)) + ) + ] + ) ); /* --------------------------------------- */ buffer := B.Buffer(3); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer2 := B.Buffer(3); for (i in Iter.range(0, 2)) { - buffer.add(i); + buffer.add(i) }; var buffer3 = B.Buffer(3); for (i in Iter.range(2, 5)) { - buffer3.add(i); + buffer3.add(i) }; run( @@ -2062,30 +2062,30 @@ run( test( "empty buffers", B.compare(B.Buffer(3), B.Buffer(2), Nat.compare), - M.equals(OrderTestable(#equal)), + M.equals(OrderTestable(#equal)) ), test( "non-empty buffers equal", B.compare(buffer, B.clone(buffer), Nat.compare), - M.equals(OrderTestable(#equal)), + M.equals(OrderTestable(#equal)) ), test( "non-empty and empty buffers", B.compare(buffer, B.Buffer(3), Nat.compare), - M.equals(OrderTestable(#greater)), + M.equals(OrderTestable(#greater)) ), test( "non-empty buffers mismatching lengths", B.compare(buffer, buffer2, Nat.compare), - M.equals(OrderTestable(#greater)), + M.equals(OrderTestable(#greater)) ), test( "non-empty buffers lexicographic difference", B.compare(buffer, buffer3, Nat.compare), - M.equals(OrderTestable(#less)), - ), - ], - ), + M.equals(OrderTestable(#less)) + ) + ] + ) ); /* --------------------------------------- */ @@ -2094,9 +2094,9 @@ var nestedBuffer = B.Buffer>(3); for (i in Iter.range(0, 4)) { let innerBuffer = B.Buffer(2); for (j in if (i % 2 == 0) { Iter.range(0, 4) } else { Iter.range(0, 3) }) { - innerBuffer.add(j); + innerBuffer.add(j) }; - nestedBuffer.add(innerBuffer); + nestedBuffer.add(innerBuffer) }; nestedBuffer.add(B.Buffer(2)); @@ -2109,22 +2109,22 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(45)), + M.equals(T.nat(45)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 3, 4])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 3, 4])) + ) + ] + ) ); /* --------------------------------------- */ nestedBuffer := B.Buffer>(3); for (i in Iter.range(0, 4)) { - nestedBuffer.add(B.Buffer(2)); + nestedBuffer.add(B.Buffer(2)) }; buffer := B.flatten(nestedBuffer); @@ -2136,15 +2136,15 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2159,28 +2159,28 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 7)) { - buffer.add(i); + buffer.add(i) }; buffer2.clear(); for (i in Iter.range(0, 6)) { - buffer2.add(i); + buffer2.add(i) }; buffer3.clear(); @@ -2199,32 +2199,32 @@ run( test( "even elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [7, 6, 5, 4, 3, 2, 1, 0])), + M.equals(T.array(T.natTestable, [7, 6, 5, 4, 3, 2, 1, 0])) ), test( "odd elements", B.toArray(buffer2), - M.equals(T.array(T.natTestable, [6, 5, 4, 3, 2, 1, 0])), + M.equals(T.array(T.natTestable, [6, 5, 4, 3, 2, 1, 0])) ), test( "empty", B.toArray(buffer3), - M.equals(T.array(T.natTestable, [] : [Nat])), + M.equals(T.array(T.natTestable, [] : [Nat])) ), test( "singleton", B.toArray(buffer4), - M.equals(T.array(T.natTestable, [3])), - ), - ], - ), + M.equals(T.array(T.natTestable, [3])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; var partition = B.partition(buffer, func x = x % 2 == 0); @@ -2238,44 +2238,44 @@ run( test( "capacity of true buffer", buffer2.capacity(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "elements of true buffer", B.toArray(buffer2), - M.equals(T.array(T.natTestable, [0, 2, 4])), + M.equals(T.array(T.natTestable, [0, 2, 4])) ), test( "capacity of false buffer", buffer3.capacity(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "elements of false buffer", B.toArray(buffer3), - M.equals(T.array(T.natTestable, [1, 3, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [1, 3, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 3)) { - buffer.add(i); + buffer.add(i) }; for (i in Iter.range(10, 13)) { - buffer.add(i); + buffer.add(i) }; buffer2.clear(); for (i in Iter.range(2, 5)) { - buffer2.add(i); + buffer2.add(i) }; for (i in Iter.range(13, 15)) { - buffer2.add(i); + buffer2.add(i) }; buffer := B.merge(buffer, buffer2, Nat.compare); @@ -2287,22 +2287,22 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(23)), + M.equals(T.nat(23)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 2, 3, 3, 4, 5, 10, 11, 12, 13, 13, 14, 15])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 2, 3, 3, 4, 5, 10, 11, 12, 13, 13, 14, 15])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 3)) { - buffer.add(i); + buffer.add(i) }; buffer2.clear(); @@ -2316,15 +2316,15 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2341,15 +2341,15 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2371,15 +2371,15 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 1, 2, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 1, 2, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2400,15 +2400,15 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 1, 2, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 1, 2, 5])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2423,15 +2423,15 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2447,22 +2447,22 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [2] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [2] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; partition := B.split(buffer, 2); @@ -2476,32 +2476,32 @@ run( test( "capacity prefix", buffer2.capacity(), - M.equals(T.nat(3)), + M.equals(T.nat(3)) ), test( "elements prefix", B.toArray(buffer2), - M.equals(T.array(T.natTestable, [0, 1])), + M.equals(T.array(T.natTestable, [0, 1])) ), test( "capacity suffix", buffer3.capacity(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "elements suffix", B.toArray(buffer3), - M.equals(T.array(T.natTestable, [2, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [2, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; partition := B.split(buffer, 0); @@ -2515,32 +2515,32 @@ run( test( "capacity prefix", buffer2.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements prefix", B.toArray(buffer2), - M.equals(T.array(T.natTestable, [] : [Nat])), + M.equals(T.array(T.natTestable, [] : [Nat])) ), test( "capacity suffix", buffer3.capacity(), - M.equals(T.nat(9)), + M.equals(T.nat(9)) ), test( "elements suffix", B.toArray(buffer3), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; partition := B.split(buffer, 6); @@ -2554,25 +2554,25 @@ run( test( "capacity prefix", buffer2.capacity(), - M.equals(T.nat(9)), + M.equals(T.nat(9)) ), test( "elements prefix", B.toArray(buffer2), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4, 5])) ), test( "capacity suffix", buffer3.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements suffix", B.toArray(buffer3), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2580,10 +2580,10 @@ buffer.clear(); buffer2.clear(); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; for (i in Iter.range(0, 3)) { - buffer2.add(i); + buffer2.add(i) }; var bufferPairs = B.zip(buffer, buffer2); @@ -2595,15 +2595,15 @@ run( test( "capacity", bufferPairs.capacity(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "elements", B.toArray(bufferPairs), - M.equals(T.array(T.tuple2Testable(T.natTestable, T.natTestable), [(0, 0), (1, 1), (2, 2), (3, 3)])), - ), - ], - ), + M.equals(T.array(T.tuple2Testable(T.natTestable, T.natTestable), [(0, 0), (1, 1), (2, 2), (3, 3)])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2611,7 +2611,7 @@ buffer.clear(); buffer2.clear(); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; bufferPairs := B.zip(buffer, buffer2); @@ -2623,15 +2623,15 @@ run( test( "capacity", bufferPairs.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements", B.toArray(bufferPairs), - M.equals(T.array(T.tuple2Testable(T.natTestable, T.natTestable), [] : [(Nat, Nat)])), - ), - ], - ), + M.equals(T.array(T.tuple2Testable(T.natTestable, T.natTestable), [] : [(Nat, Nat)])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2647,15 +2647,15 @@ run( test( "capacity", bufferPairs.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements", B.toArray(bufferPairs), - M.equals(T.array(T.tuple2Testable(T.natTestable, T.natTestable), [] : [(Nat, Nat)])), - ), - ], - ), + M.equals(T.array(T.tuple2Testable(T.natTestable, T.natTestable), [] : [(Nat, Nat)])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2663,10 +2663,10 @@ buffer.clear(); buffer2.clear(); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; for (i in Iter.range(0, 3)) { - buffer2.add(i); + buffer2.add(i) }; buffer3 := B.zipWith(buffer, buffer2, Nat.add); @@ -2678,15 +2678,15 @@ run( test( "capacity", buffer3.capacity(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "elements", B.toArray(buffer3), - M.equals(T.array(T.natTestable, [0, 2, 4, 6])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 2, 4, 6])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2694,7 +2694,7 @@ buffer.clear(); buffer2.clear(); for (i in Iter.range(0, 5)) { - buffer.add(i); + buffer.add(i) }; buffer3 := B.zipWith(buffer, buffer2, Nat.add); @@ -2706,22 +2706,22 @@ run( test( "capacity", buffer3.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements", B.toArray(buffer3), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 8)) { - buffer.add(i); + buffer.add(i) }; var chunks = B.chunk(buffer, 2); @@ -2733,40 +2733,40 @@ run( test( "num chunks", chunks.size(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "chunk 0 capacity", chunks.get(0).capacity(), - M.equals(T.nat(3)), + M.equals(T.nat(3)) ), test( "chunk 0 elements", B.toArray(chunks.get(0)), - M.equals(T.array(T.natTestable, [0, 1])), + M.equals(T.array(T.natTestable, [0, 1])) ), test( "chunk 2 capacity", chunks.get(2).capacity(), - M.equals(T.nat(3)), + M.equals(T.nat(3)) ), test( "chunk 2 elements", B.toArray(chunks.get(2)), - M.equals(T.array(T.natTestable, [4, 5])), + M.equals(T.array(T.natTestable, [4, 5])) ), test( "chunk 4 capacity", chunks.get(4).capacity(), - M.equals(T.nat(3)), + M.equals(T.nat(3)) ), test( "chunk 4 elements", B.toArray(chunks.get(4)), - M.equals(T.array(T.natTestable, [8])), - ), - ], - ), + M.equals(T.array(T.natTestable, [8])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2781,17 +2781,17 @@ run( test( "num chunks", chunks.size(), - M.equals(T.nat(0)), - ), - ], - ), + M.equals(T.nat(0)) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; chunks := B.chunk(buffer, 10); @@ -2803,15 +2803,15 @@ run( test( "num chunks", chunks.size(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "chunk 0 elements", B.toArray(chunks.get(0)), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2836,40 +2836,40 @@ run( test( "num groups", groups.size(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "group 0 capacity", groups.get(0).capacity(), - M.equals(T.nat(9)), + M.equals(T.nat(9)) ), test( "group 0 elements", B.toArray(groups.get(0)), - M.equals(T.array(T.natTestable, [2, 2, 2])), + M.equals(T.array(T.natTestable, [2, 2, 2])) ), test( "group 1 capacity", groups.get(1).capacity(), - M.equals(T.nat(6)), + M.equals(T.nat(6)) ), test( "group 1 elements", B.toArray(groups.get(1)), - M.equals(T.array(T.natTestable, [1])), + M.equals(T.array(T.natTestable, [1])) ), test( "group 4 capacity", groups.get(4).capacity(), - M.equals(T.nat(2)), + M.equals(T.nat(2)) ), test( "group 4 elements", B.toArray(groups.get(4)), - M.equals(T.array(T.natTestable, [1, 1])), - ), - ], - ), + M.equals(T.array(T.natTestable, [1, 1])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2884,17 +2884,17 @@ run( test( "num groups", groups.size(), - M.equals(T.nat(0)), - ), - ], - ), + M.equals(T.nat(0)) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(0); + buffer.add(0) }; groups := B.groupBy(buffer, Nat.equal); @@ -2906,22 +2906,22 @@ run( test( "num groups", groups.size(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "group 0 elements", B.toArray(groups.get(0)), - M.equals(T.array(T.natTestable, [0, 0, 0, 0, 0])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 0, 0, 0, 0])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer := B.prefix(buffer, 3); @@ -2933,15 +2933,15 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2])) + ) + ] + ) ); /* --------------------------------------- */ @@ -2956,22 +2956,22 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer := B.prefix(buffer, 5); @@ -2983,28 +2983,28 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(8)), + M.equals(T.nat(8)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer2.clear(); for (i in Iter.range(0, 2)) { - buffer2.add(i); + buffer2.add(i) }; buffer3.clear(); @@ -3020,53 +3020,53 @@ run( test( "normal prefix", B.isPrefixOf(buffer2, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "identical buffers", B.isPrefixOf(buffer, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "one empty buffer", B.isPrefixOf(B.Buffer(3), buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "not prefix", B.isPrefixOf(buffer3, buffer, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not prefix from length", B.isPrefixOf(buffer, buffer2, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not prefix of empty", B.isPrefixOf(buffer, B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "empty prefix of empty", B.isPrefixOf(B.Buffer(4), B.Buffer(3), Nat.equal), - M.equals(T.bool(true)), - ), - ], - ), + M.equals(T.bool(true)) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer2.clear(); for (i in Iter.range(0, 2)) { - buffer2.add(i); + buffer2.add(i) }; buffer3.clear(); @@ -3082,47 +3082,47 @@ run( test( "normal prefix", B.isStrictPrefixOf(buffer2, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "identical buffers", B.isStrictPrefixOf(buffer, buffer, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "one empty buffer", B.isStrictPrefixOf(B.Buffer(3), buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "not prefix", B.isStrictPrefixOf(buffer3, buffer, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not prefix from length", B.isStrictPrefixOf(buffer, buffer2, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not prefix of empty", B.isStrictPrefixOf(buffer, B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "empty prefix of empty", B.isStrictPrefixOf(B.Buffer(4), B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), - ), - ], - ), + M.equals(T.bool(false)) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer := B.subBuffer(buffer, 1, 3); @@ -3134,22 +3134,22 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [1, 2, 3])), - ), - ], - ), + M.equals(T.array(T.natTestable, [1, 2, 3])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; run( @@ -3159,44 +3159,44 @@ run( test( "prefix", B.prefix(buffer, 3), - M.equals({ { item = B.subBuffer(buffer, 0, 3) } and NatBufferTestable }), + M.equals({ { item = B.subBuffer(buffer, 0, 3) } and NatBufferTestable }) ), test( "suffix", B.suffix(buffer, 3), - M.equals({ { item = B.subBuffer(buffer, 2, 3) } and NatBufferTestable }), + M.equals({ { item = B.subBuffer(buffer, 2, 3) } and NatBufferTestable }) ), test( "empty", B.toArray(B.subBuffer(buffer, 2, 0)), - M.equals(T.array(T.natTestable, [] : [Nat])), + M.equals(T.array(T.natTestable, [] : [Nat])) ), test( "trivial", B.subBuffer(buffer, 0, buffer.size()), - M.equals({ { item = buffer } and NatBufferTestable }), - ), - ], - ), + M.equals({ { item = buffer } and NatBufferTestable }) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer2.clear(); for (i in Iter.range(0, 2)) { - buffer2.add(i); + buffer2.add(i) }; buffer3.clear(); for (i in Iter.range(1, 3)) { - buffer3.add(i); + buffer3.add(i) }; run( @@ -3206,70 +3206,70 @@ run( test( "normal subBuffer", B.isSubBufferOf(buffer3, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "prefix", B.isSubBufferOf(buffer2, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "identical buffers", B.isSubBufferOf(buffer, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "one empty buffer", B.isSubBufferOf(B.Buffer(3), buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "not subBuffer", B.isSubBufferOf(buffer3, buffer2, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not subBuffer from length", B.isSubBufferOf(buffer, buffer2, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not subBuffer of empty", B.isSubBufferOf(buffer, B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "empty subBuffer of empty", B.isSubBufferOf(B.Buffer(4), B.Buffer(3), Nat.equal), - M.equals(T.bool(true)), - ), - ], - ), + M.equals(T.bool(true)) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer2.clear(); for (i in Iter.range(0, 2)) { - buffer2.add(i); + buffer2.add(i) }; buffer3.clear(); for (i in Iter.range(1, 3)) { - buffer3.add(i); + buffer3.add(i) }; buffer4 := B.Buffer(4); for (i in Iter.range(3, 4)) { - buffer4.add(i); + buffer4.add(i) }; run( @@ -3279,57 +3279,57 @@ run( test( "normal strict subBuffer", B.isStrictSubBufferOf(buffer3, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "prefix", B.isStrictSubBufferOf(buffer2, buffer, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "suffix", B.isStrictSubBufferOf(buffer4, buffer, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "identical buffers", B.isStrictSubBufferOf(buffer, buffer, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "one empty buffer", B.isStrictSubBufferOf(B.Buffer(3), buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "not subBuffer", B.isStrictSubBufferOf(buffer3, buffer2, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not subBuffer from length", B.isStrictSubBufferOf(buffer, buffer2, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not subBuffer of empty", B.isStrictSubBufferOf(buffer, B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "empty not strict subBuffer of empty", B.isStrictSubBufferOf(B.Buffer(4), B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), - ), - ], - ), + M.equals(T.bool(false)) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer := B.suffix(buffer, 3); @@ -3341,22 +3341,22 @@ run( test( "capacity", buffer.capacity(), - M.equals(T.nat(5)), + M.equals(T.nat(5)) ), test( "elements", B.toArray(buffer), - M.equals(T.array(T.natTestable, [2, 3, 4])), - ), - ], - ), + M.equals(T.array(T.natTestable, [2, 3, 4])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; run( @@ -3366,27 +3366,27 @@ run( test( "empty", B.toArray(B.prefix(buffer, 0)), - M.equals(T.array(T.natTestable, [] : [Nat])), + M.equals(T.array(T.natTestable, [] : [Nat])) ), test( "trivial", B.prefix(buffer, buffer.size()), - M.equals({ { item = buffer } and NatBufferTestable }), - ), - ], - ), + M.equals({ { item = buffer } and NatBufferTestable }) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer2.clear(); for (i in Iter.range(3, 4)) { - buffer2.add(i); + buffer2.add(i) }; buffer3.clear(); @@ -3402,52 +3402,52 @@ run( test( "normal suffix", B.isSuffixOf(buffer2, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "identical buffers", B.isSuffixOf(buffer, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "one empty buffer", B.isSuffixOf(B.Buffer(3), buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "not suffix", B.isSuffixOf(buffer3, buffer, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not suffix from length", B.isSuffixOf(buffer, buffer2, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not suffix of empty", B.isSuffixOf(buffer, B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "empty suffix of empty", B.isSuffixOf(B.Buffer(4), B.Buffer(3), Nat.equal), - M.equals(T.bool(true)), - ), - ], - ), + M.equals(T.bool(true)) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; buffer2.clear(); for (i in Iter.range(3, 4)) { - buffer2.add(i); + buffer2.add(i) }; buffer3.clear(); @@ -3463,47 +3463,47 @@ run( test( "normal suffix", B.isStrictSuffixOf(buffer2, buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "identical buffers", B.isStrictSuffixOf(buffer, buffer, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "one empty buffer", B.isStrictSuffixOf(B.Buffer(3), buffer, Nat.equal), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), test( "not suffix", B.isStrictSuffixOf(buffer3, buffer, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not suffix from length", B.isStrictSuffixOf(buffer, buffer2, Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "not suffix of empty", B.isStrictSuffixOf(buffer, B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), test( "empty suffix of empty", B.isStrictSuffixOf(B.Buffer(4), B.Buffer(3), Nat.equal), - M.equals(T.bool(false)), - ), - ], - ), + M.equals(T.bool(false)) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; run( @@ -3513,22 +3513,22 @@ run( test( "normal case", B.toArray(B.takeWhile(buffer, func x = x < 3)), - M.equals(T.array(T.natTestable, [0, 1, 2])), + M.equals(T.array(T.natTestable, [0, 1, 2])) ), test( "empty", B.toArray(B.takeWhile(B.Buffer(3), func x = x < 3)), - M.equals(T.array(T.natTestable, [] : [Nat])), - ), - ], - ), + M.equals(T.array(T.natTestable, [] : [Nat])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 4)) { - buffer.add(i); + buffer.add(i) }; run( @@ -3538,32 +3538,32 @@ run( test( "normal case", B.toArray(B.dropWhile(buffer, func x = x < 3)), - M.equals(T.array(T.natTestable, [3, 4])), + M.equals(T.array(T.natTestable, [3, 4])) ), test( "empty", B.toArray(B.dropWhile(B.Buffer(3), func x = x < 3)), - M.equals(T.array(T.natTestable, [] : [Nat])), + M.equals(T.array(T.natTestable, [] : [Nat])) ), test( "drop all", B.toArray(B.dropWhile(buffer, func _ = true)), - M.equals(T.array(T.natTestable, [] : [Nat])), + M.equals(T.array(T.natTestable, [] : [Nat])) ), test( "drop none", B.toArray(B.dropWhile(buffer, func _ = false)), - M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4])), - ), - ], - ), + M.equals(T.array(T.natTestable, [0, 1, 2, 3, 4])) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(1, 6)) { - buffer.add(i); + buffer.add(i) }; run( @@ -3573,37 +3573,37 @@ run( test( "find in middle", B.binarySearch(2, buffer, Nat.compare), - M.equals(T.optional(T.natTestable, ?1)), + M.equals(T.optional(T.natTestable, ?1)) ), test( "find first", B.binarySearch(1, buffer, Nat.compare), - M.equals(T.optional(T.natTestable, ?0)), + M.equals(T.optional(T.natTestable, ?0)) ), test( "find last", B.binarySearch(6, buffer, Nat.compare), - M.equals(T.optional(T.natTestable, ?5)), + M.equals(T.optional(T.natTestable, ?5)) ), test( "not found to the right", B.binarySearch(10, buffer, Nat.compare), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), test( "not found to the left", B.binarySearch(0, buffer, Nat.compare), - M.equals(T.optional(T.natTestable, null : ?Nat)), - ), - ], - ), + M.equals(T.optional(T.natTestable, null : ?Nat)) + ) + ] + ) ); /* --------------------------------------- */ buffer.clear(); for (i in Iter.range(0, 6)) { - buffer.add(i); + buffer.add(i) }; run( @@ -3613,30 +3613,30 @@ run( test( "find in middle", B.indexOf(2, buffer, Nat.equal), - M.equals(T.optional(T.natTestable, ?2)), + M.equals(T.optional(T.natTestable, ?2)) ), test( "find first", B.indexOf(0, buffer, Nat.equal), - M.equals(T.optional(T.natTestable, ?0)), + M.equals(T.optional(T.natTestable, ?0)) ), test( "find last", B.indexOf(6, buffer, Nat.equal), - M.equals(T.optional(T.natTestable, ?6)), + M.equals(T.optional(T.natTestable, ?6)) ), test( "not found", B.indexOf(10, buffer, Nat.equal), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), test( "empty", B.indexOf(100, B.Buffer(3), Nat.equal), - M.equals(T.optional(T.natTestable, null : ?Nat)), - ), - ], - ), + M.equals(T.optional(T.natTestable, null : ?Nat)) + ) + ] + ) ); /* --------------------------------------- */ @@ -3659,30 +3659,30 @@ run( test( "find in middle", B.lastIndexOf(10, buffer, Nat.equal), - M.equals(T.optional(T.natTestable, ?6)), + M.equals(T.optional(T.natTestable, ?6)) ), test( "find only", B.lastIndexOf(3, buffer, Nat.equal), - M.equals(T.optional(T.natTestable, ?7)), + M.equals(T.optional(T.natTestable, ?7)) ), test( "find last", B.lastIndexOf(0, buffer, Nat.equal), - M.equals(T.optional(T.natTestable, ?8)), + M.equals(T.optional(T.natTestable, ?8)) ), test( "not found", B.lastIndexOf(100, buffer, Nat.equal), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), test( "empty", B.lastIndexOf(100, B.Buffer(3), Nat.equal), - M.equals(T.optional(T.natTestable, null : ?Nat)), - ), - ], - ), + M.equals(T.optional(T.natTestable, null : ?Nat)) + ) + ] + ) ); /* --------------------------------------- */ @@ -3704,38 +3704,38 @@ run( test( "find in middle", B.indexOfBuffer(B.fromArray([1, 10, 1]), buffer, Nat.equal), - M.equals(T.optional(T.natTestable, ?2)), + M.equals(T.optional(T.natTestable, ?2)) ), test( "find first", B.indexOfBuffer(B.fromArray([2, 2, 1, 10]), buffer, Nat.equal), - M.equals(T.optional(T.natTestable, ?0)), + M.equals(T.optional(T.natTestable, ?0)) ), test( "find last", B.indexOfBuffer(B.fromArray([0]), buffer, Nat.equal), - M.equals(T.optional(T.natTestable, ?7)), + M.equals(T.optional(T.natTestable, ?7)) ), test( "not found", B.indexOfBuffer(B.fromArray([99, 100, 1]), buffer, Nat.equal), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), test( "search for empty buffer", B.indexOfBuffer(B.fromArray([]), buffer, Nat.equal), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), test( "search through empty buffer", B.indexOfBuffer(B.fromArray([1, 2, 3]), B.Buffer(2), Nat.equal), - M.equals(T.optional(T.natTestable, null : ?Nat)), + M.equals(T.optional(T.natTestable, null : ?Nat)) ), test( "search for empty in empty", B.indexOfBuffer(B.Buffer(2), B.Buffer(3), Nat.equal), - M.equals(T.optional(T.natTestable, null : ?Nat)), - ), - ], - ), -); + M.equals(T.optional(T.natTestable, null : ?Nat)) + ) + ] + ) +) diff --git a/test/charTest.mo b/test/charTest.mo index a778002d..aa0b1295 100644 --- a/test/charTest.mo +++ b/test/charTest.mo @@ -61,4 +61,4 @@ assert (not Char.isUppercase('x')); assert (Char.isAlphabetic('a')); assert (Char.isAlphabetic('京')); -assert (not Char.isAlphabetic('㋡')); +assert (not Char.isAlphabetic('㋡')) diff --git a/test/dequeTest.mo b/test/dequeTest.mo index d3e0a035..3f023f2c 100644 --- a/test/dequeTest.mo +++ b/test/dequeTest.mo @@ -7,7 +7,7 @@ import D "mo:base/Debug"; do { var l = Deque.empty(); for (i in Iter.range(0, 100)) { - l := Deque.pushBack(l, i); + l := Deque.pushBack(l, i) }; for (i in Iter.range(0, 100)) { let x = Deque.peekFront(l); @@ -16,14 +16,14 @@ do { l := l2; switch x { case null assert false; - case (?x) assert (x == y); - }; + case (?x) assert (x == y) + } }; - case null { assert false }; + case null { assert false } }; - assert (O.unwrap(x) == i); + assert (O.unwrap(x) == i) }; - O.assertNull(Deque.peekFront(l)); + O.assertNull(Deque.peekFront(l)) }; // test for Deque @@ -31,7 +31,7 @@ do { var l = Deque.empty(); for (i in Iter.range(1, 100)) { l := Deque.pushFront(l, -i); - l := Deque.pushBack(l, i); + l := Deque.pushBack(l, i) }; label F for (i in Iter.revRange(100, -100)) { if (i == 0) continue F; @@ -41,11 +41,11 @@ do { l := l2; switch x { case null assert false; - case (?x) assert (x == y); - }; + case (?x) assert (x == y) + } }; - case null { assert false }; + case null { assert false } }; - assert (O.unwrap(x) == i); - }; -}; + assert (O.unwrap(x) == i) + } +} diff --git a/test/floatTest.mo b/test/floatTest.mo index 997cf9cb..c75e41fa 100644 --- a/test/floatTest.mo +++ b/test/floatTest.mo @@ -7,70 +7,70 @@ do { Debug.print(" abs"); assert (Float.abs(1.1) == 1.1); - assert (Float.abs(-1.1) == 1.1); + assert (Float.abs(-1.1) == 1.1) }; do { Debug.print(" ceil"); - assert (Float.ceil(1.1) == 2.0); + assert (Float.ceil(1.1) == 2.0) }; do { Debug.print(" floor"); - assert (Float.floor(1.1) == 1.0); + assert (Float.floor(1.1) == 1.0) }; do { Debug.print(" trunc"); - assert (Float.trunc(1.0012345789) == 1.0); + assert (Float.trunc(1.0012345789) == 1.0) }; do { Debug.print(" nearest"); assert (Float.nearest(1.00001) == 1.0); - assert (Float.nearest(1.99999) == 2.0); + assert (Float.nearest(1.99999) == 2.0) }; do { Debug.print(" min"); - assert (Float.min(1.1, 2.2) == 1.1); + assert (Float.min(1.1, 2.2) == 1.1) }; do { Debug.print(" max"); - assert (Float.max(1.1, 2.2) == 2.2); + assert (Float.max(1.1, 2.2) == 2.2) }; do { Debug.print(" sin"); - assert (Float.sin(0.0) == 0.0); + assert (Float.sin(0.0) == 0.0) }; do { Debug.print(" cos"); - assert (Float.cos(0.0) == 1.0); + assert (Float.cos(0.0) == 1.0) }; do { Debug.print(" toFloat64"); assert (Float.toInt64(1e10) == (10000000000 : Int64)); - assert (Float.toInt64(-1e10) == (-10000000000 : Int64)); + assert (Float.toInt64(-1e10) == (-10000000000 : Int64)) }; do { Debug.print(" ofFloat64"); assert (Float.fromInt64(10000000000) == 1e10); - assert (Float.fromInt64(-10000000000) == -1e10); + assert (Float.fromInt64(-10000000000) == -1e10) }; do { @@ -80,19 +80,19 @@ do { assert (Float.format(#fix 6, 20.12345678901) == "20.123457"); assert (Float.format(#exp 9, 20.12345678901) == "2.012345679e+01"); assert (Float.format(#gen 12, 20.12345678901) == "20.123456789"); - assert (Float.format(#hex 10, 20.12345678901) == "0x1.41f9add374p+4"); + assert (Float.format(#hex 10, 20.12345678901) == "0x1.41f9add374p+4") }; do { Debug.print(" Pi: " # Float.toText(Float.pi)); Debug.print(" arccos(-1.0): " # Float.toText(Float.arccos(-1.))); - assert (Float.pi == Float.arccos(-1.)); + assert (Float.pi == Float.arccos(-1.)) }; do { Debug.print(" e: " # debug_show (Float.toText(Float.e))); Debug.print(" exp(1): " # debug_show (Float.toText(Float.exp(1)))); - assert (Float.e == Float.exp(1)); -}; + assert (Float.e == Float.exp(1)) +} diff --git a/test/funcTest.mo b/test/funcTest.mo index 87011457..ebc797ce 100644 --- a/test/funcTest.mo +++ b/test/funcTest.mo @@ -12,7 +12,7 @@ do { let isOdd = Function.compose(not_, isEven); assert (isOdd(0) == false); - assert (isOdd(1)); + assert (isOdd(1)) }; do { @@ -20,5 +20,5 @@ do { assert (Function.const(true)("abc")); assert (Function.const(false)("abc") == false); - assert (Function.const(false)("abc", "abc") == false); -}; + assert (Function.const(false)("abc", "abc") == false) +} diff --git a/test/hashMapTest.mo b/test/hashMapTest.mo index cc67b6a4..e9ba6e27 100644 --- a/test/hashMapTest.mo +++ b/test/hashMapTest.mo @@ -27,8 +27,8 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (b.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // ensure original has each key-value pair present in clone @@ -36,25 +36,25 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (a.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // ensure clone has each key present in original for (k in a.keys()) { switch (b.get(k)) { case null { assert false }; - case (?_) {}; - }; + case (?_) {} + } }; // ensure clone has each value present in original for (v in a.vals()) { var foundMatch = false; for (w in b.vals()) { - if (v == w) { foundMatch := true }; + if (v == w) { foundMatch := true } }; - assert foundMatch; + assert foundMatch }; // do some more operations: @@ -62,26 +62,26 @@ debug { a.put("banana", 2222); switch (a.remove("pear")) { case null { assert false }; - case (?three) { assert three == 3 }; + case (?three) { assert three == 3 } }; a.delete("avocado"); // check them: switch (a.get("apple")) { case (?1111) {}; - case _ { assert false }; + case _ { assert false } }; switch (a.get("banana")) { case (?2222) {}; - case _ { assert false }; + case _ { assert false } }; switch (a.get("pear")) { case null {}; - case (?_) { assert false }; + case (?_) { assert false } }; switch (a.get("avocado")) { case null {}; - case (?_) { assert false }; + case (?_) { assert false } }; // undo operations above: @@ -91,8 +91,8 @@ debug { case null { assert false }; case (?one) { assert one == 1; // ...and revert - a.put("apple", 1); - }; + a.put("apple", 1) + } }; a.put("banana", 2); a.put("pear", 3); @@ -103,8 +103,8 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (b.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // ensure original has each key-value pair present in clone @@ -112,8 +112,8 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (a.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // test fromIter method @@ -124,8 +124,8 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (c.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // b agrees with each entry of c @@ -133,14 +133,14 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (b.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // Issue #228 let d = H.HashMap(50, Text.equal, Text.hash); switch (d.remove("test")) { case null {}; - case (?_) { assert false }; - }; -}; + case (?_) { assert false } + } +} diff --git a/test/heapTest.mo b/test/heapTest.mo index efd1deea..6b3b172a 100644 --- a/test/heapTest.mo +++ b/test/heapTest.mo @@ -10,20 +10,20 @@ do { for (i in I.revRange(100, 0)) { pq.put(i); let x = pq.peekMin(); - assert (O.unwrap(x) == i); + assert (O.unwrap(x) == i) }; for (i in I.range(0, 100)) { pq.put(i); let x = pq.peekMin(); - assert (O.unwrap(x) == 0); + assert (O.unwrap(x) == 0) }; for (i in I.range(0, 100)) { pq.deleteMin(); let x = pq.peekMin(); pq.deleteMin(); - assert (O.unwrap(x) == i); + assert (O.unwrap(x) == i) }; - O.assertNull(pq.peekMin()); + O.assertNull(pq.peekMin()) }; // fromIter @@ -34,18 +34,18 @@ do { for (i in I.range(0, 10)) { let x = pq.peekMin(); assert (O.unwrap(x) == i); - pq.deleteMin(); + pq.deleteMin() }; - O.assertNull(pq.peekMin()); + O.assertNull(pq.peekMin()) }; do { let pq = H.fromIter([].vals(), order); - O.assertNull(pq.peekMin()); + O.assertNull(pq.peekMin()) }; do { let pq = H.fromIter([100].vals(), order); - assert (O.unwrap(pq.peekMin()) == 100); - }; -}; + assert (O.unwrap(pq.peekMin()) == 100) + } +} diff --git a/test/int8Test.mo b/test/int8Test.mo index 2945c455..f9335e7c 100644 --- a/test/int8Test.mo +++ b/test/int8Test.mo @@ -4,4 +4,4 @@ import Int8 "mo:base/Int8"; assert (Int8.fromIntWrap(256) == (0 : Int8)); assert (Int8.fromIntWrap(-256) == (0 : Int8)); assert (Int8.fromIntWrap(128) == (-128 : Int8)); -assert (Int8.fromIntWrap(255) == (-1 : Int8)); +assert (Int8.fromIntWrap(255) == (-1 : Int8)) diff --git a/test/intTest.mo b/test/intTest.mo index bbfdafbc..84b1b665 100644 --- a/test/intTest.mo +++ b/test/intTest.mo @@ -10,7 +10,7 @@ do { assert (Int.add(0, 1) == 1); assert (1 == Int.add(1, 0)); assert (Int.add(0, 1) == Int.add(1, 0)); - assert (Int.add(1, 2) == Int.add(2, 1)); + assert (Int.add(1, 2) == Int.add(2, 1)) }; do { @@ -19,5 +19,5 @@ do { assert (Int.toText(0) == "0"); assert (Int.toText(-0) == "0"); assert (Int.toText(1234) == "1234"); - assert (Int.toText(-1234) == "-1234"); -}; + assert (Int.toText(-1234) == "-1234") +} diff --git a/test/iterTest.mo b/test/iterTest.mo index ff012313..072fbc38 100644 --- a/test/iterTest.mo +++ b/test/iterTest.mo @@ -14,15 +14,15 @@ do { for ((range, expected, revExpected) in tests.vals()) { var x = ""; for (i in Iter.range(range)) { - x := x # Nat.toText(i); + x := x # Nat.toText(i) }; assert (x == expected); x := ""; for (i in Iter.revRange(range)) { - x := x # Int.toText(i); + x := x # Int.toText(i) }; - assert (x == revExpected); - }; + assert (x == revExpected) + } }; do { @@ -37,19 +37,19 @@ do { xs.vals(), func(x : Text, i : Nat) { y := y # x; - z += i; - }, + z += i + } ); assert (y == "abcdef"); - assert (z == 15); + assert (z == 15) }; do { Debug.print(" map"); let isEven = func(x : Int) : Bool { - x % 2 == 0; + x % 2 == 0 }; let _actual = Iter.map([1, 2, 3].vals(), isEven); @@ -59,15 +59,15 @@ do { let expected = [false, true, false]; for (i in actual.keys()) { - assert (actual[i] == expected[i]); - }; + assert (actual[i] == expected[i]) + } }; do { Debug.print(" filter"); let isOdd = func(x : Int) : Bool { - x % 2 == 1; + x % 2 == 1 }; let _actual = Iter.filter([1, 2, 3].vals(), isOdd); @@ -76,7 +76,7 @@ do { let expected = [1, 3]; - assert (Array.freeze(actual) == expected); + assert (Array.freeze(actual) == expected) }; do { @@ -87,8 +87,8 @@ do { switch (y.next()) { case null { assert false }; - case (?z) { assert (x == z) }; - }; + case (?z) { assert (x == z) } + } }; do { @@ -101,8 +101,8 @@ do { Iter.iterate(_actual, func(x, i) { actual[i] := x }); for (i in actual.keys()) { - assert (actual[i] == expected[i]); - }; + assert (actual[i] == expected[i]) + } }; do { @@ -115,8 +115,8 @@ do { Iter.iterate(_actual, func(x, i) { actual[i] := x }); for (i in actual.keys()) { - assert (actual[i] == expected[i]); - }; + assert (actual[i] == expected[i]) + } }; do { @@ -130,8 +130,8 @@ do { Iter.iterate(_actual, func(x, i) { actual[i] := x }); for (i in actual.keys()) { - assert (actual[i] == expected[i]); - }; + assert (actual[i] == expected[i]) + } }; do { @@ -143,8 +143,8 @@ do { assert (actual.size() == expected.size()); for (i in actual.keys()) { - assert (actual[i] == expected[i]); - }; + assert (actual[i] == expected[i]) + } }; do { @@ -156,8 +156,8 @@ do { assert (actual.size() == expected.size()); for (i in actual.keys()) { - assert (actual[i] == expected[i]); - }; + assert (actual[i] == expected[i]) + } }; do { @@ -165,7 +165,7 @@ do { let expected : List.List = ?(1, ?(2, ?(3, List.nil()))); let actual = Iter.toList([1, 2, 3].vals()); - assert List.equal(expected, actual, func(x1, x2) { x1 == x2 }); + assert List.equal(expected, actual, func(x1, x2) { x1 == x2 }) }; do { @@ -174,5 +174,5 @@ do { let input : [Nat] = [4, 3, 1, 2, 5]; let expected : [Nat] = [1, 2, 3, 4, 5]; let actual = Iter.toArray(Iter.sort(input.vals(), Nat.compare)); - assert Array.equal(expected, actual, func(x1, x2) { x1 == x2 }); -}; + assert Array.equal(expected, actual, func(x1, x2) { x1 == x2 }) +} diff --git a/test/listTest.mo b/test/listTest.mo index e14ef1cb..14778a2f 100644 --- a/test/listTest.mo +++ b/test/listTest.mo @@ -13,14 +13,14 @@ func opnatEq(a : ?Nat, b : ?Nat) : Bool { switch (a, b) { case (null, null) { true }; case (?aaa, ?bbb) { aaa == bbb }; - case (_, _) { false }; - }; + case (_, _) { false } + } }; func opnat_isnull(a : ?Nat) : Bool { switch a { case (null) { true }; - case (?aaa) { false }; - }; + case (?aaa) { false } + } }; // ## Construction @@ -84,7 +84,7 @@ do { let array = [1, 2, 3]; let actual = List.fromArray(array); - assert List.equal(expected, actual, func(x1, x2) { x1 == x2 }); + assert List.equal(expected, actual, func(x1, x2) { x1 == x2 }) }; do { @@ -94,7 +94,7 @@ do { let array = [var 1, 2, 3]; let actual = List.fromVarArray(array); - assert List.equal(expected, actual, func(x1, x2) { x1 == x2 }); + assert List.equal(expected, actual, func(x1, x2) { x1 == x2 }) }; do { @@ -107,8 +107,8 @@ do { assert (actual.size() == expected.size()); for (i in actual.keys()) { - assert (actual[i] == expected[i]); - }; + assert (actual[i] == expected[i]) + } }; do { @@ -121,8 +121,8 @@ do { assert (actual.size() == expected.size()); for (i in actual.keys()) { - assert (actual[i] == expected[i]); - }; + assert (actual[i] == expected[i]) + } }; do { @@ -136,17 +136,17 @@ do { Iter.iterate(_actual, func(x, i) { actual[i] := x }); for (i in actual.keys()) { - assert (actual[i] == expected[i]); - }; + assert (actual[i] == expected[i]) + } }; func makeNatural(x : Int) : Result.Result = if (x >= 0) { - #ok(Int.abs(x)); + #ok(Int.abs(x)) } else { #err(Int.toText(x) # " is not a natural number.") }; func listRes(itm : Result.Result, Text>) : T.TestableItem, Text>> { let resT = T.resultTestable(T.listTestable(T.intTestable), T.textTestable); - { display = resT.display; equals = resT.equals; item = itm }; + { display = resT.display; equals = resT.equals; item = itm } }; let mapResult = Suite.suite( @@ -155,24 +155,24 @@ let mapResult = Suite.suite( Suite.test( "empty list", List.mapResult(List.nil(), makeNatural), - M.equals(listRes(#ok(List.nil()))), + M.equals(listRes(#ok(List.nil()))) ), Suite.test( "success", List.mapResult(?(1, ?(2, ?(3, null))), makeNatural), - M.equals(listRes(#ok(?(1, ?(2, ?(3, null)))))), + M.equals(listRes(#ok(?(1, ?(2, ?(3, null)))))) ), Suite.test( "fail fast", List.mapResult(?(-1, ?(2, ?(3, null))), makeNatural), - M.equals(listRes(#err("-1 is not a natural number."))), + M.equals(listRes(#err("-1 is not a natural number."))) ), Suite.test( "fail last", List.mapResult(?(1, ?(2, ?(-3, null))), makeNatural), - M.equals(listRes(#err("-3 is not a natural number."))), - ), - ], + M.equals(listRes(#err("-3 is not a natural number."))) + ) + ] ); Suite.run(Suite.suite("List", [mapResult])); @@ -184,17 +184,17 @@ let replicate = Suite.suite( "empty-list", List.replicate(0, 0), M.equals( - T.list(T.natTestable, List.nil()), - ), + T.list(T.natTestable, List.nil()) + ) ), Suite.test( "small-list", List.replicate(3, 0), M.equals( - T.list(T.natTestable, ?(0, ?(0, ?(0, null)))), - ), - ), - ], + T.list(T.natTestable, ?(0, ?(0, ?(0, null)))) + ) + ) + ] ); let tabulate = Suite.suite( @@ -204,24 +204,24 @@ let tabulate = Suite.suite( "empty-list", List.tabulate(0, func i { i }), M.equals( - T.list(T.natTestable, List.nil()), - ), + T.list(T.natTestable, List.nil()) + ) ), Suite.test( "small-list", List.tabulate(3, func i { i * 2 }), M.equals( - T.list(T.natTestable, ?(0, ?(2, ?(4, null)))), - ), + T.list(T.natTestable, ?(0, ?(2, ?(4, null)))) + ) ), Suite.test( "large-list", List.tabulate(10000, func i { 0 }), M.equals( - T.list(T.natTestable, List.replicate(10000, 0)), - ), - ), - ], + T.list(T.natTestable, List.replicate(10000, 0)) + ) + ) + ] ); let append = Suite.suite( @@ -231,23 +231,23 @@ let append = Suite.suite( "small-list", List.append( List.tabulate(10, func i { i }), - List.tabulate(10, func i { i + 10 }), + List.tabulate(10, func i { i + 10 }) ), M.equals( - T.list(T.natTestable, List.tabulate(20, func i { i })), - ), + T.list(T.natTestable, List.tabulate(20, func i { i })) + ) ), Suite.test( "large-list", List.append( List.tabulate(10000, func i { i }), - List.tabulate(10000, func i { i + 10000 }), + List.tabulate(10000, func i { i + 10000 }) ), M.equals( - T.list(T.natTestable, List.tabulate(20000, func i { i })), - ), - ), - ], + T.list(T.natTestable, List.tabulate(20000, func i { i })) + ) + ) + ] ); -Suite.run(Suite.suite("List", [mapResult, replicate, tabulate, append])); +Suite.run(Suite.suite("List", [mapResult, replicate, tabulate, append])) diff --git a/test/natTest.mo b/test/natTest.mo index 8626e5a9..c0e2214b 100644 --- a/test/natTest.mo +++ b/test/natTest.mo @@ -10,12 +10,12 @@ do { assert (Nat.add(0, 1) == 1); assert (1 == Nat.add(1, 0)); assert (Nat.add(0, 1) == Nat.add(1, 0)); - assert (Nat.add(1, 2) == Nat.add(2, 1)); + assert (Nat.add(1, 2) == Nat.add(2, 1)) }; do { Debug.print(" toText"); assert (Nat.toText(0) == "0"); - assert (Nat.toText(1234) == "1234"); -}; + assert (Nat.toText(1234) == "1234") +} diff --git a/test/noneTest.mo b/test/noneTest.mo index ca44c938..1dac1b4c 100644 --- a/test/noneTest.mo +++ b/test/noneTest.mo @@ -8,6 +8,6 @@ do { Debug.print(" impossible"); func showNone(x : None) : Text { - None.impossible(x); - }; -}; + None.impossible(x) + } +} diff --git a/test/optionTest.mo b/test/optionTest.mo index 24b69ef6..2b2c0f1d 100644 --- a/test/optionTest.mo +++ b/test/optionTest.mo @@ -14,12 +14,12 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (false); + assert (false) }; case (_, _) { - assert (true); - }; - }; + assert (true) + } + } }; do { @@ -30,19 +30,19 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (false); + assert (false) }; case (_, _) { - assert (true); - }; - }; + assert (true) + } + } }; do { Debug.print(" non-null function, null value"); let isEven = func(x : Int) : Bool { - x % 2 == 0; + x % 2 == 0 }; let actual = Option.apply(null, ?isEven); @@ -50,19 +50,19 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (false); + assert (false) }; case (_, _) { - assert (true); - }; - }; + assert (true) + } + } }; do { Debug.print(" non-null function, non-null value"); let isEven = func(x : Int) : Bool { - x % 2 == 0; + x % 2 == 0 }; let actual = Option.apply(?0, ?isEven); @@ -70,12 +70,12 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (actual_ == expected_); + assert (actual_ == expected_) }; case (_, _) { - assert (false); - }; - }; + assert (false) + } + } }; }; @@ -88,10 +88,10 @@ do { let safeInt = func(x : Int) : ?Int { if (x > 9007199254740991) { - null; + null } else { - ?x; - }; + ?x + } }; let actual = Option.chain(null, safeInt); @@ -99,12 +99,12 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (false); + assert (false) }; case (_, _) { - assert (true); - }; - }; + assert (true) + } + } }; do { @@ -112,10 +112,10 @@ do { let safeInt = func(x : Int) : ?Int { if (x > 9007199254740991) { - null; + null } else { - ?x; - }; + ?x + } }; let actual = Option.chain(?9007199254740992, safeInt); @@ -123,12 +123,12 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (false); + assert (false) }; case (_, _) { - assert (true); - }; - }; + assert (true) + } + } }; do { @@ -136,10 +136,10 @@ do { let safeInt = func(x : Int) : ?Int { if (x > 9007199254740991) { - null; + null } else { - ?x; - }; + ?x + } }; let actual = Option.chain(?0, safeInt); @@ -147,12 +147,12 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (actual_ == expected_); + assert (actual_ == expected_) }; case (_, _) { - assert (false); - }; - }; + assert (false) + } + } }; }; @@ -168,12 +168,12 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (false); + assert (false) }; case (_, _) { - assert (true); - }; - }; + assert (true) + } + } }; do { @@ -183,12 +183,12 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (actual_ == expected_); + assert (actual_ == expected_) }; case (_, _) { - assert (false); - }; - }; + assert (false) + } + } }; }; @@ -200,7 +200,7 @@ do { Debug.print(" null value"); let isEven = func(x : Int) : Bool { - x % 2 == 0; + x % 2 == 0 }; let actual = Option.map(null, isEven); @@ -208,19 +208,19 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (false); + assert (false) }; case (_, _) { - assert (true); - }; - }; + assert (true) + } + } }; do { Debug.print(" non-null value"); let isEven = func(x : Int) : Bool { - x % 2 == 0; + x % 2 == 0 }; let actual = Option.map(?0, isEven); @@ -228,12 +228,12 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (actual_ == expected_); + assert (actual_ == expected_) }; case (_, _) { - assert (false); - }; - }; + assert (false) + } + } }; }; @@ -245,8 +245,8 @@ do { Option.iterate(?(1), func(x : Nat) { witness += 1 }); assert (witness == 1); Option.iterate(null, func(x : Nat) { witness += 1 }); - assert (witness == 1); - }; + assert (witness == 1) + } }; do { @@ -257,10 +257,10 @@ do { switch (actual, expected) { case (?actual_, ?expected_) { - assert (actual_ == expected_); + assert (actual_ == expected_) }; case (_, _) { - assert (false); - }; - }; -}; + assert (false) + } + } +} diff --git a/test/orderTest.mo b/test/orderTest.mo index 422b1eff..85c89634 100644 --- a/test/orderTest.mo +++ b/test/orderTest.mo @@ -8,7 +8,7 @@ do { assert (Order.isLess(#less)); assert (not Order.isLess(#equal)); - assert (not Order.isLess(#greater)); + assert (not Order.isLess(#greater)) }; do { @@ -16,7 +16,7 @@ do { assert (not Order.isEqual(#less)); assert (Order.isEqual(#equal)); - assert (not Order.isEqual(#greater)); + assert (not Order.isEqual(#greater)) }; do { @@ -24,5 +24,5 @@ do { assert (not Order.isGreater(#less)); assert (not Order.isGreater(#equal)); - assert (Order.isGreater(#greater)); -}; + assert (Order.isGreater(#greater)) +} diff --git a/test/resultTest.mo b/test/resultTest.mo index 2f035534..e8522365 100644 --- a/test/resultTest.mo +++ b/test/resultTest.mo @@ -8,11 +8,11 @@ import M "mo:matchers/Matchers"; import T "mo:matchers/Testable"; func makeNatural(x : Int) : Result.Result = if (x >= 0) { - #ok(Int.abs(x)); + #ok(Int.abs(x)) } else { #err(Int.toText(x) # " is not a natural number.") }; func largerThan10(x : Nat) : Result.Result = if (x > 10) { #ok(x) } else { - #err(Int.toText(x) # " is not larger than 10."); + #err(Int.toText(x) # " is not larger than 10.") }; let chain = Suite.suite( @@ -21,19 +21,19 @@ let chain = Suite.suite( Suite.test( "ok -> ok", Result.chain(makeNatural(11), largerThan10), - M.equals(T.result(T.natTestable, T.textTestable, #ok(11))), + M.equals(T.result(T.natTestable, T.textTestable, #ok(11))) ), Suite.test( "ok -> err", Result.chain(makeNatural(5), largerThan10), - M.equals(T.result(T.natTestable, T.textTestable, #err("5 is not larger than 10."))), + M.equals(T.result(T.natTestable, T.textTestable, #err("5 is not larger than 10."))) ), Suite.test( "err", Result.chain(makeNatural(-5), largerThan10), - M.equals(T.result(T.natTestable, T.textTestable, #err("-5 is not a natural number."))), - ), - ], + M.equals(T.result(T.natTestable, T.textTestable, #err("-5 is not a natural number."))) + ) + ] ); let flatten = Suite.suite( @@ -42,19 +42,19 @@ let flatten = Suite.suite( Suite.test( "ok -> ok", Result.flatten(#ok(#ok(10))), - M.equals(T.result(T.natTestable, T.textTestable, #ok(10))), + M.equals(T.result(T.natTestable, T.textTestable, #ok(10))) ), Suite.test( "err", Result.flatten(#err("wrong")), - M.equals(T.result(T.natTestable, T.textTestable, #err("wrong"))), + M.equals(T.result(T.natTestable, T.textTestable, #err("wrong"))) ), Suite.test( "ok -> err", Result.flatten(#ok(#err("wrong"))), - M.equals(T.result(T.natTestable, T.textTestable, #err("wrong"))), - ), - ], + M.equals(T.result(T.natTestable, T.textTestable, #err("wrong"))) + ) + ] ); let iterate = Suite.suite( @@ -66,8 +66,8 @@ let iterate = Suite.suite( tests := Array.append(tests, [Suite.test("ok", counter, M.equals(T.nat(5)))]); Result.iterate(makeNatural(-10), func(x : Nat) { counter += x }); tests := Array.append(tests, [Suite.test("err", counter, M.equals(T.nat(5)))]); - tests; - }, + tests + } ); let suite = Suite.suite( @@ -75,8 +75,8 @@ let suite = Suite.suite( [ chain, flatten, - iterate, - ], + iterate + ] ); -Suite.run(suite); +Suite.run(suite) diff --git a/test/stackTest.mo b/test/stackTest.mo index 283c77f0..bf707dd2 100644 --- a/test/stackTest.mo +++ b/test/stackTest.mo @@ -5,11 +5,11 @@ import O "mo:base/Option"; do { var s = Stack.Stack(); for (i in Iter.range(0, 100)) { - s.push(i); + s.push(i) }; for (i in Iter.revRange(100, 0)) { let x = s.pop(); - assert (O.unwrap(x) == i); + assert (O.unwrap(x) == i) }; - assert (s.isEmpty()); -}; + assert (s.isEmpty()) +} diff --git a/test/testLenClamp.mo b/test/testLenClamp.mo index ddc28c2b..17459cae 100644 --- a/test/testLenClamp.mo +++ b/test/testLenClamp.mo @@ -10,11 +10,11 @@ func lenClamp(l : List, max : Nat) : ?Nat { switch l { case null { ?i }; case (?(_, t)) { - if (i >= max) { null } else { rec(t, max, i + 1) }; - }; - }; + if (i >= max) { null } else { rec(t, max, i + 1) } + } + } }; - rec(l, max, 0); + rec(l, max, 0) }; var s = 0; @@ -27,8 +27,8 @@ while (s < 10) { Debug.print(debug_show ({ l = List.toArray(l); m; o })); assert (s == List.size(l)); assert (if (s <= m) { o == ?s } else { o == null }); - m += 1; + m += 1 }; l := List.push(s +1, l); - s += 1; -}; + s += 1 +} diff --git a/test/textTest.mo b/test/textTest.mo index bc455ceb..4a320e7a 100644 --- a/test/textTest.mo +++ b/test/textTest.mo @@ -16,19 +16,19 @@ let { run; test; suite } = Suite; func charT(c : Char) : T.TestableItem = { item = c; display = Text.fromChar; - equals = Char.equal; + equals = Char.equal }; func blobT(b : Blob) : T.TestableItem = { item = b; display = func(b : Blob) : Text { debug_show (b) }; - equals = Blob.equal; + equals = Blob.equal }; func ordT(o : Order.Order) : T.TestableItem = { item = o; display = func(o : Order.Order) : Text { debug_show (o) }; - equals = Order.equal; + equals = Order.equal }; func optTextT(ot : ?Text) : T.TestableItem = T.optional(T.textTestable, ot); @@ -42,10 +42,10 @@ func iterT(c : [Char]) : T.TestableItem> = { switch (cs1.next(), cs2.next()) { case (null, null) return true; case (?c1, ?c2) if (c1 != c2) return false; - case (_, _) return false; - }; - }; - }; + case (_, _) return false + } + } + } }; // TODO: generalize and move to Iter.mo @@ -58,10 +58,10 @@ func textIterT(c : [Text]) : T.TestableItem> = { switch (ts1.next(), ts2.next()) { case (null, null) return true; case (?t1, ?t2) if (t1 != t2) return false; - case (_, _) return false; - }; - }; - }; + case (_, _) return false + } + } + } }; run( @@ -71,30 +71,30 @@ run( test( "size-0", Text.size(""), - M.equals(T.nat 0), + M.equals(T.nat 0) ), test( "size-1", Text.size("a"), - M.equals(T.nat 1), + M.equals(T.nat 1) ), test( "size-2", Text.size("abcdefghijklmnopqrstuvwxyz"), - M.equals(T.nat 26), + M.equals(T.nat 26) ), test( "size-3", Text.size("☃"), - M.equals(T.nat 1), + M.equals(T.nat 1) ), test( "size-4", Text.size("☃☃"), - M.equals(T.nat 2), - ), - ], - ), + M.equals(T.nat 2) + ) + ] + ) ); run( @@ -104,28 +104,28 @@ run( test( "toIter-0", Text.toIter(""), - M.equals(iterT([])), + M.equals(iterT([])) ), test( "toIter-1", Text.toIter("a"), - M.equals(iterT(['a'])), + M.equals(iterT(['a'])) ), test( "toIter-2", Text.toIter("abc"), - M.equals(iterT(['a', 'b', 'c'])), + M.equals(iterT(['a', 'b', 'c'])) ), do { let a = Array.tabulate(1000, func i = Char.fromNat32(65 +% Nat32.fromIntWrap(i % 26))); test( "fromIter-2", Text.toIter(Text.join("", Array.map(a, Char.toText).vals())), - M.equals(iterT a), - ); - }, - ], - ), + M.equals(iterT a) + ) + } + ] + ) ); run( @@ -135,28 +135,28 @@ run( test( "fromIter-0", Text.fromIter(([].vals())), - M.equals(T.text("")), + M.equals(T.text("")) ), test( "fromIter-1", Text.fromIter((['a'].vals())), - M.equals(T.text "a"), + M.equals(T.text "a") ), test( "fromIter-2", Text.fromIter((['a', 'b', 'c'].vals())), - M.equals(T.text "abc"), + M.equals(T.text "abc") ), do { let a = Array.tabulate(1000, func i = Char.fromNat32(65 +% Nat32.fromIntWrap(i % 26))); test( "fromIter-3", Text.fromIter(a.vals()), - M.equals(T.text(Text.join("", Array.map(a, Char.toText).vals()))), - ); - }, - ], - ), + M.equals(T.text(Text.join("", Array.map(a, Char.toText).vals()))) + ) + } + ] + ) ); run( @@ -166,25 +166,25 @@ run( test( "concat-0", Text.concat("", ""), - M.equals(T.text("")), + M.equals(T.text("")) ), test( "concat-1", Text.concat("", "b"), - M.equals(T.text "b"), + M.equals(T.text "b") ), test( "concat-2", Text.concat("a", "b"), - M.equals(T.text "ab"), + M.equals(T.text "ab") ), test( "concat-3", Text.concat("abcdefghijklmno", "pqrstuvwxyz"), - M.equals(T.text "abcdefghijklmnopqrstuvwxyz"), - ), - ], - ), + M.equals(T.text "abcdefghijklmnopqrstuvwxyz") + ) + ] + ) ); run( @@ -194,38 +194,38 @@ run( test( "join-0", Text.join("", (["", ""].vals())), - M.equals(T.text("")), + M.equals(T.text("")) ), test( "join-1", Text.join("", (["", "b"].vals())), - M.equals(T.text "b"), + M.equals(T.text "b") ), test( "join-2", Text.join("", (["a", "bb", "ccc", "dddd"].vals())), - M.equals(T.text "abbcccdddd"), + M.equals(T.text "abbcccdddd") ), do { let a = Array.tabulate(1000, func i = Char.fromNat32(65 +% Nat32.fromIntWrap(i % 26))); test( "join-3", Text.join("", Array.map(a, Char.toText).vals()), - M.equals(T.text(Text.fromIter(a.vals()))), - ); + M.equals(T.text(Text.fromIter(a.vals()))) + ) }, test( "join-4", Text.join("", ([].vals())), - M.equals(T.text ""), + M.equals(T.text "") ), test( "join-5", Text.join("", (["aaa"].vals())), - M.equals(T.text "aaa"), - ), - ], - ), + M.equals(T.text "aaa") + ) + ] + ) ); run( @@ -235,38 +235,38 @@ run( test( "join-0", Text.join(",", (["", ""].vals())), - M.equals(T.text(",")), + M.equals(T.text(",")) ), test( "join-1", Text.join(",", (["", "b"].vals())), - M.equals(T.text ",b"), + M.equals(T.text ",b") ), test( "join-2", Text.join(",", (["a", "bb", "ccc", "dddd"].vals())), - M.equals(T.text "a,bb,ccc,dddd"), + M.equals(T.text "a,bb,ccc,dddd") ), do { let a = Array.tabulate(1000, func i = Char.fromNat32(65 +% Nat32.fromIntWrap(i % 26))); test( "join-3", Text.join("", Array.map(a, Char.toText).vals()), - M.equals(T.text(Text.fromIter(a.vals()))), - ); + M.equals(T.text(Text.fromIter(a.vals()))) + ) }, test( "join-4", Text.join(",", ([].vals())), - M.equals(T.text ""), + M.equals(T.text "") ), test( "join-5", Text.join(",", (["aaa"].vals())), - M.equals(T.text "aaa"), - ), - ], - ), + M.equals(T.text "aaa") + ) + ] + ) ); run( @@ -276,32 +276,32 @@ run( test( "split-char-empty", Text.split("", #char ';'), - M.equals(textIterT([])), + M.equals(textIterT([])) ), test( "split-char-none", Text.split("abc", #char ';'), - M.equals(textIterT(["abc"])), + M.equals(textIterT(["abc"])) ), test( "split-char-empties2", Text.split(";", #char ';'), - M.equals(textIterT(["", ""])), + M.equals(textIterT(["", ""])) ), test( "split-char-empties3", Text.split(";;", #char ';'), - M.equals(textIterT(["", "", ""])), + M.equals(textIterT(["", "", ""])) ), test( "split-char-singles", Text.split("a;b;;c;;;d", #char ';'), - M.equals(textIterT(["a", "b", "", "c", "", "", "d"])), + M.equals(textIterT(["a", "b", "", "c", "", "", "d"])) ), test( "split-char-mixed", Text.split("a;;;ab;;abc;", #char ';'), - M.equals(textIterT(["a", "", "", "ab", "", "abc", ""])), + M.equals(textIterT(["a", "", "", "ab", "", "abc", ""])) ), do { let a = Array.tabulate(1000, func _ = "abc"); @@ -309,8 +309,8 @@ run( test( "split-char-large", Text.split(t, #char ';'), - M.equals(textIterT a), - ); + M.equals(textIterT a) + ) }, do { let a = Array.tabulate(100000, func _ = "abc"); @@ -318,11 +318,11 @@ run( test( "split-char-very-large", Text.split(t, #char ';'), - M.equals(textIterT a), - ); - }, - ], - ), + M.equals(textIterT a) + ) + } + ] + ) ); do { @@ -334,32 +334,32 @@ do { test( "split-pred-empty", Text.split("", pat), - M.equals(textIterT([])), + M.equals(textIterT([])) ), test( "split-pred-none", Text.split("abc", pat), - M.equals(textIterT(["abc"])), + M.equals(textIterT(["abc"])) ), test( "split-pred-empties2", Text.split(";", pat), - M.equals(textIterT(["", ""])), + M.equals(textIterT(["", ""])) ), test( "split-pred-empties3", Text.split(";!", pat), - M.equals(textIterT(["", "", ""])), + M.equals(textIterT(["", "", ""])) ), test( "split-pred-singles", Text.split("a;b;!c!;;d", pat), - M.equals(textIterT(["a", "b", "", "c", "", "", "d"])), + M.equals(textIterT(["a", "b", "", "c", "", "", "d"])) ), test( "split-pred-mixed", Text.split("a;!;ab;!abc;", pat), - M.equals(textIterT(["a", "", "", "ab", "", "abc", ""])), + M.equals(textIterT(["a", "", "", "ab", "", "abc", ""])) ), do { let a = Array.tabulate(1000, func _ = "abc"); @@ -367,8 +367,8 @@ do { test( "split-pred-large", Text.split(t, pat), - M.equals(textIterT a), - ); + M.equals(textIterT a) + ) }, do { let a = Array.tabulate(10000, func _ = "abc"); @@ -376,12 +376,12 @@ do { test( "split-pred-very-large", Text.split(t, pat), - M.equals(textIterT a), - ); - }, - ], - ), - ); + M.equals(textIterT a) + ) + } + ] + ) + ) }; do { @@ -393,32 +393,32 @@ do { test( "split-pat-empty", Text.split("", pat), - M.equals(textIterT([])), + M.equals(textIterT([])) ), test( "split-pat-none", Text.split("abc", pat), - M.equals(textIterT(["abc"])), + M.equals(textIterT(["abc"])) ), test( "split-pat-empties2", Text.split("PAT", pat), - M.equals(textIterT(["", ""])), + M.equals(textIterT(["", ""])) ), test( "split-pat-empties3", Text.split("PATPAT", pat), - M.equals(textIterT(["", "", ""])), + M.equals(textIterT(["", "", ""])) ), test( "split-pat-singles", Text.split("aPATbPATPATcPATPATPATd", pat), - M.equals(textIterT(["a", "b", "", "c", "", "", "d"])), + M.equals(textIterT(["a", "b", "", "c", "", "", "d"])) ), test( "split-pat-mixed", Text.split("aPATPATPATabPATPATabcPAT", pat), - M.equals(textIterT(["a", "", "", "ab", "", "abc", ""])), + M.equals(textIterT(["a", "", "", "ab", "", "abc", ""])) ), do { let a = Array.tabulate(1000, func _ = "abc"); @@ -426,8 +426,8 @@ do { test( "split-pat-large", Text.split(t, pat), - M.equals(textIterT a), - ); + M.equals(textIterT a) + ) }, do { let a = Array.tabulate(10000, func _ = "abc"); @@ -435,12 +435,12 @@ do { test( "split-pat-very-large", Text.split(t, pat), - M.equals(textIterT a), - ); - }, - ], - ), - ); + M.equals(textIterT a) + ) + } + ] + ) + ) }; run( @@ -450,32 +450,32 @@ run( test( "tokens-char-empty", Text.tokens("", #char ';'), - M.equals(textIterT([])), + M.equals(textIterT([])) ), test( "tokens-char-none", Text.tokens("abc", #char ';'), - M.equals(textIterT(["abc"])), + M.equals(textIterT(["abc"])) ), test( "tokens-char-empties2", Text.tokens(";", #char ';'), - M.equals(textIterT([])), + M.equals(textIterT([])) ), test( "tokens-char-empties3", Text.tokens(";;", #char ';'), - M.equals(textIterT([])), + M.equals(textIterT([])) ), test( "tokens-char-singles", Text.tokens("a;b;;c;;;d", #char ';'), - M.equals(textIterT(["a", "b", "c", "d"])), + M.equals(textIterT(["a", "b", "c", "d"])) ), test( "tokens-char-mixed", Text.tokens("a;;;ab;;abc;", #char ';'), - M.equals(textIterT(["a", "ab", "abc"])), + M.equals(textIterT(["a", "ab", "abc"])) ), do { let a = Array.tabulate(1000, func _ = "abc"); @@ -483,8 +483,8 @@ run( test( "tokens-char-large", Text.tokens(t, #char ';'), - M.equals(textIterT a), - ); + M.equals(textIterT a) + ) }, do { let a = Array.tabulate(100000, func _ = "abc"); @@ -492,11 +492,11 @@ run( test( "tokens-char-very-large", Text.tokens(t, #char ';'), - M.equals(textIterT a), - ); - }, - ], - ), + M.equals(textIterT a) + ) + } + ] + ) ); run( @@ -506,40 +506,40 @@ run( test( "startsWith-both-empty", Text.startsWith("", #text ""), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "startsWith-empty-text", Text.startsWith("", #text "abc"), - M.equals(T.bool false), + M.equals(T.bool false) ), test( "startsWith-empty-pat", Text.startsWith("abc", #text ""), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "startsWith-1", Text.startsWith("a", #text "b"), - M.equals(T.bool false), + M.equals(T.bool false) ), test( "startsWith-2", Text.startsWith("abc", #text "abc"), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "startsWith-3", Text.startsWith("abcd", #text "ab"), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "startsWith-4", Text.startsWith("abcdefghijklmnopqrstuvwxyz", #text "abcdefghijklmno"), - M.equals(T.bool true), - ), - ], - ), + M.equals(T.bool true) + ) + ] + ) ); run( @@ -549,40 +549,40 @@ run( test( "endsWith-both-empty", Text.endsWith("", #text ""), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "endsWith-empty-text", Text.endsWith("", #text "abc"), - M.equals(T.bool false), + M.equals(T.bool false) ), test( "endsWith-empty-pat", Text.endsWith("abc", #text ""), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "endsWith-1", Text.endsWith("a", #text "b"), - M.equals(T.bool false), + M.equals(T.bool false) ), test( "endsWith-2", Text.endsWith("abc", #text "abc"), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "endsWith-3", Text.endsWith("abcd", #text "cd"), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "endsWith-4", Text.endsWith("abcdefghijklmnopqrstuvwxyz", #text "pqrstuvwxyz"), - M.equals(T.bool true), - ), - ], - ), + M.equals(T.bool true) + ) + ] + ) ); run( @@ -592,50 +592,50 @@ run( test( "contains-start", Text.contains("abcd", #text "ab"), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "contains-empty", Text.contains("abc", #text ""), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "contains-false", Text.contains("ab", #text "bc"), - M.equals(T.bool false), + M.equals(T.bool false) ), test( "contains-exact", Text.contains("abc", #text "abc"), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "contains-within", Text.contains("abcdefghijklmnopqrstuvwxyz", #text "qrst"), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "contains-front", Text.contains("abcdefghijklmnopqrstuvwxyz", #text "abcdefg"), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "contains-end", Text.contains("abcdefghijklmnopqrstuvwxyz", #text "xyz"), - M.equals(T.bool true), + M.equals(T.bool true) ), test( "contains-false", Text.contains("abcdefghijklmnopqrstuvwxyz", #text "lkj"), - M.equals(T.bool false), + M.equals(T.bool false) ), test( "contains-empty-nonempty", Text.contains("", #text "xyz"), - M.equals(T.bool false), - ), - ], - ), + M.equals(T.bool false) + ) + ] + ) ); run( @@ -645,55 +645,55 @@ run( test( "replace-start", Text.replace("abcd", #text "ab", "AB"), - M.equals(T.text "ABcd"), + M.equals(T.text "ABcd") ), test( "replace-empty", Text.replace("abc", #text "", "AB"), - M.equals(T.text "ABaABbABcAB"), + M.equals(T.text "ABaABbABcAB") ), test( "replace-none", Text.replace("ab", #text "bc", "AB"), - M.equals(T.text "ab"), + M.equals(T.text "ab") ), test( "replace-exact", Text.replace("ab", #text "ab", "AB"), - M.equals(T.text "AB"), + M.equals(T.text "AB") ), test( "replace-several", Text.replace("abcdabghijabmnopqrstuabwxab", #text "ab", "AB"), - M.equals(T.text "ABcdABghijABmnopqrstuABwxAB"), + M.equals(T.text "ABcdABghijABmnopqrstuABwxAB") ), test( "replace-delete", Text.replace("abcdabghijabmnopqrstuabwxab", #text "ab", ""), - M.equals(T.text "cdghijmnopqrstuwx"), + M.equals(T.text "cdghijmnopqrstuwx") ), test( "replace-pred", Text.replace("abcdefghijklmnopqrstuvwxyz", #predicate(func(c : Char) : Bool { c < 'm' }), ""), - M.equals(T.text "mnopqrstuvwxyz"), + M.equals(T.text "mnopqrstuvwxyz") ), test( "replace-partial", Text.replace("123", #text "124", "ABC"), - M.equals(T.text "123"), + M.equals(T.text "123") ), test( "replace-partial-2", Text.replace("12341235124", #text "124", "ABC"), - M.equals(T.text "12341235ABC"), + M.equals(T.text "12341235ABC") ), test( "replace-partial-3", Text.replace("111234123511124", #text "124", "ABC"), - M.equals(T.text "111234123511ABC"), - ), - ], - ), + M.equals(T.text "111234123511ABC") + ) + ] + ) ); run( @@ -703,35 +703,35 @@ run( test( "stripStart-none", Text.stripStart("cd", #text "ab"), - M.equals(optTextT(null)), + M.equals(optTextT(null)) ), test( "stripStart-one", Text.stripStart("abcd", #text "ab"), - M.equals(optTextT(?"cd")), + M.equals(optTextT(?"cd")) ), test( "stripStart-two", Text.stripStart("abababcd", #text "ab"), - M.equals(optTextT(?"ababcd")), + M.equals(optTextT(?"ababcd")) ), test( "stripStart-only", Text.stripStart("ababababab", #text "ab"), - M.equals(optTextT(?"abababab")), + M.equals(optTextT(?"abababab")) ), test( "stripStart-empty", Text.stripStart("abcdef", #text ""), - M.equals(optTextT(?"abcdef")), + M.equals(optTextT(?"abcdef")) ), test( "stripStart-tooshort", Text.stripStart("abcdef", #text "abcdefg"), - M.equals(optTextT(null)), - ), - ], - ), + M.equals(optTextT(null)) + ) + ] + ) ); run( @@ -741,40 +741,40 @@ run( test( "stripEnd-exact", Text.stripEnd("cd", #text "cd"), - M.equals(optTextT(?"")), + M.equals(optTextT(?"")) ), test( "stripEnd-one", Text.stripEnd("abcd", #text "cd"), - M.equals(optTextT(?"ab")), + M.equals(optTextT(?"ab")) ), test( "stripEnd-three", Text.stripEnd("abcdcdcd", #text "cd"), - M.equals(optTextT(?"abcdcd")), + M.equals(optTextT(?"abcdcd")) ), test( "stripEnd-many", Text.stripEnd("cdcdcdcdcdcdcd", #text "cd"), - M.equals(optTextT(?"cdcdcdcdcdcd")), + M.equals(optTextT(?"cdcdcdcdcdcd")) ), test( "stripEnd-empty-pat", Text.stripEnd("abcdef", #text ""), - M.equals(optTextT(?"abcdef")), + M.equals(optTextT(?"abcdef")) ), test( "stripEnd-empty", Text.stripEnd("", #text "cd"), - M.equals(optTextT null), + M.equals(optTextT null) ), test( "stripEnd-tooshort", Text.stripEnd("bcdef", #text "abcdef"), - M.equals(optTextT null), - ), - ], - ), + M.equals(optTextT null) + ) + ] + ) ); run( @@ -784,30 +784,30 @@ run( test( "trimStart-none", Text.trimStart("cd", #text "ab"), - M.equals(T.text "cd"), + M.equals(T.text "cd") ), test( "trimStart-one", Text.trimStart("abcd", #text "ab"), - M.equals(T.text "cd"), + M.equals(T.text "cd") ), test( "trimStart-two", Text.trimStart("abababcd", #text "ab"), - M.equals(T.text "cd"), + M.equals(T.text "cd") ), test( "trimStart-only", Text.trimStart("ababababab", #text "ab"), - M.equals(T.text ""), + M.equals(T.text "") ), test( "trimStart-empty", Text.trimStart("abcdef", #text ""), - M.equals(T.text "abcdef"), - ), - ], - ), + M.equals(T.text "abcdef") + ) + ] + ) ); run( @@ -817,35 +817,35 @@ run( test( "trimEnd-exact", Text.trimEnd("cd", #text "cd"), - M.equals(T.text ""), + M.equals(T.text "") ), test( "trimEnd-one", Text.trimEnd("abcd", #text "cd"), - M.equals(T.text "ab"), + M.equals(T.text "ab") ), test( "trimEnd-three", Text.trimEnd("abcdcdcd", #text "cd"), - M.equals(T.text "ab"), + M.equals(T.text "ab") ), test( "trimEnd-many", Text.trimEnd("cdcdcdcdcdcdcd", #text "cd"), - M.equals(T.text ""), + M.equals(T.text "") ), test( "trimEnd-empty-pat", Text.trimEnd("abcdef", #text ""), - M.equals(T.text "abcdef"), + M.equals(T.text "abcdef") ), test( "trimEnd-empty", Text.trimEnd("", #text "cd"), - M.equals(T.text ""), - ), - ], - ), + M.equals(T.text "") + ) + ] + ) ); run( @@ -855,35 +855,35 @@ run( test( "trim-exact", Text.trim("cd", #text "cd"), - M.equals(T.text ""), + M.equals(T.text "") ), test( "trim-one", Text.trim("cdabcd", #text "cd"), - M.equals(T.text "ab"), + M.equals(T.text "ab") ), test( "trim-three", Text.trim("cdcdcdabcdcdcd", #text "cd"), - M.equals(T.text "ab"), + M.equals(T.text "ab") ), test( "trim-many", Text.trim("cdcdcdcdcdcdcd", #text "cd"), - M.equals(T.text ""), + M.equals(T.text "") ), test( "trim-empty-pat", Text.trim("abcdef", #text ""), - M.equals(T.text "abcdef"), + M.equals(T.text "abcdef") ), test( "trim-empty", Text.trim("", #text "cd"), - M.equals(T.text ""), - ), - ], - ), + M.equals(T.text "") + ) + ] + ) ); run( @@ -893,35 +893,35 @@ run( test( "compare-empties", Text.compare("", ""), - M.equals(ordT(#equal)), + M.equals(ordT(#equal)) ), test( "compare-empty-nonempty", Text.compare("", "a"), - M.equals(ordT(#less)), + M.equals(ordT(#less)) ), test( "compare-nonempty-empty", Text.compare("a", ""), - M.equals(ordT(#greater)), + M.equals(ordT(#greater)) ), test( "compare-a-a", Text.compare("a", "a"), - M.equals(ordT(#equal)), + M.equals(ordT(#equal)) ), test( "compare-a-b", Text.compare("a", "b"), - M.equals(ordT(#less)), + M.equals(ordT(#less)) ), test( "compare-b-a", Text.compare("b", "a"), - M.equals(ordT(#greater)), - ), - ], - ), + M.equals(ordT(#greater)) + ) + ] + ) ); do { @@ -933,41 +933,41 @@ do { test( "compareWith-empties", Text.compareWith("", "", cmp), - M.equals(ordT(#equal)), + M.equals(ordT(#equal)) ), test( "compareWith-empty", Text.compareWith("abc", "", cmp), - M.equals(ordT(#greater)), + M.equals(ordT(#greater)) ), test( "compareWith-equal-nonempty", Text.compareWith("abc", "abc", cmp), - M.equals(ordT(#equal)), + M.equals(ordT(#equal)) ), test( "compareWith-less-nonempty", Text.compareWith("abc", "abd", cmp), - M.equals(ordT(#less)), + M.equals(ordT(#less)) ), test( "compareWith-less-nonprefix", Text.compareWith("abc", "abcd", cmp), - M.equals(ordT(#less)), + M.equals(ordT(#less)) ), test( "compareWith-empty-nonempty", Text.compareWith("", "abcd", cmp), - M.equals(ordT(#less)), + M.equals(ordT(#less)) ), test( "compareWith-prefix", Text.compareWith("abcd", "abc", cmp), - M.equals(ordT(#greater)), - ), - ], - ), - ); + M.equals(ordT(#greater)) + ) + ] + ) + ) }; do { @@ -975,8 +975,8 @@ do { switch (Char.compare(c1, c2)) { case (#less) #greater; case (#equal) #equal; - case (#greater) #less; - }; + case (#greater) #less + } }; run( suite( @@ -985,16 +985,16 @@ do { test( "compareWith-flip-greater", Text.compareWith("abc", "abd", cmp), - M.equals(ordT(#greater)), + M.equals(ordT(#greater)) ), test( "compareWith-flip-less", Text.compareWith("abd", "abc", cmp), - M.equals(ordT(#less)), - ), - ], - ), - ); + M.equals(ordT(#less)) + ) + ] + ) + ) }; run( @@ -1004,28 +1004,28 @@ run( test( "encode-literal", Text.encodeUtf8("FooBär☃"), - M.equals(blobT("FooBär☃")), + M.equals(blobT("FooBär☃")) ), test( "encode-concat", Text.encodeUtf8("Foo" # "Bär" # "☃"), - M.equals(blobT("FooBär☃")), + M.equals(blobT("FooBär☃")) ), test( "decode-literal-good", Text.decodeUtf8("FooBär☃"), - M.equals(optTextT(?"FooBär☃")), + M.equals(optTextT(?"FooBär☃")) ), test( "decode-literal-bad1", Text.decodeUtf8("\FF"), - M.equals(optTextT(null)), + M.equals(optTextT(null)) ), test( "decode-literal-bad2", Text.decodeUtf8("\D8\00t d"), - M.equals(optTextT(null)), - ), - ], - ), -); + M.equals(optTextT(null)) + ) + ] + ) +) diff --git a/test/trieMapTest.mo b/test/trieMapTest.mo index c895c528..1aed93a1 100644 --- a/test/trieMapTest.mo +++ b/test/trieMapTest.mo @@ -36,25 +36,25 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (b.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // ensure clone has each key present in original for (k in a.keys()) { switch (b.get(k)) { case null { assert false }; - case (?_) {}; - }; + case (?_) {} + } }; // ensure clone has each value present in original for (v in a.vals()) { var foundMatch = false; for (w in b.vals()) { - if (v == w) { foundMatch := true }; + if (v == w) { foundMatch := true } }; - assert foundMatch; + assert foundMatch }; // ensure original has each key-value pair present in clone @@ -62,8 +62,8 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (a.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // do some more operations: @@ -75,19 +75,19 @@ debug { // check them: switch (a.get("apple")) { case (?1111) {}; - case _ { assert false }; + case _ { assert false } }; switch (a.get("banana")) { case (?2222) {}; - case _ { assert false }; + case _ { assert false } }; switch (a.get("pear")) { case null {}; - case (?_) { assert false }; + case (?_) { assert false } }; switch (a.get("avocado")) { case null {}; - case (?_) { assert false }; + case (?_) { assert false } }; // undo operations above: @@ -101,8 +101,8 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (b.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // ensure original has each key-value pair present in clone @@ -110,8 +110,8 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (a.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // test fromEntries method @@ -122,8 +122,8 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (c.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; + case (?w) { assert v == w } + } }; // b agrees with each entry of c @@ -131,7 +131,7 @@ debug { Prim.debugPrint(debug_show (k, v)); switch (b.get(k)) { case null { assert false }; - case (?w) { assert v == w }; - }; - }; -}; + case (?w) { assert v == w } + } + } +} diff --git a/test/trieSetTest.mo b/test/trieSetTest.mo index 91636811..4543ddbe 100644 --- a/test/trieSetTest.mo +++ b/test/trieSetTest.mo @@ -15,21 +15,21 @@ let simpleTests = do { Suite.test( "mem", TrieSet.mem(set1, 1, 1, Nat.equal), - M.equals(T.bool true), + M.equals(T.bool true) ), Suite.test( "size", TrieSet.size(set1), - M.equals(T.nat 3), + M.equals(T.nat 3) ), Suite.test( "toArray", TrieSet.toArray(set1), - M.equals(T.array(T.natTestable, [1, 2, 3])), - ), - ], + M.equals(T.array(T.natTestable, [1, 2, 3])) + ) + ] ); - Suite.run(suite); + Suite.run(suite) }; let binopTests = do { @@ -42,19 +42,19 @@ let binopTests = do { Suite.test( "union", TrieSet.toArray(TrieSet.union(a, b, Nat.equal)), - M.equals(T.array(T.natTestable, [1, 2, 3])), + M.equals(T.array(T.natTestable, [1, 2, 3])) ), Suite.test( "intersect", TrieSet.toArray(TrieSet.intersect(a, b, Nat.equal)), - M.equals(T.array(T.natTestable, [3])), + M.equals(T.array(T.natTestable, [3])) ), Suite.test( "diff", TrieSet.toArray(TrieSet.diff(a, b, Nat.equal)), - M.equals(T.array(T.natTestable, [1])), - ), - ], + M.equals(T.array(T.natTestable, [1])) + ) + ] ); - Suite.run(suite); -}; + Suite.run(suite) +} diff --git a/test/trieTest.mo b/test/trieTest.mo index 6a867316..b316515e 100644 --- a/test/trieTest.mo +++ b/test/trieTest.mo @@ -15,10 +15,10 @@ let test = Suite; // Utilities to massage types between Trie and Matchers func prettyArray(trie : Trie.Trie) : [(Nat, Nat)] { - Trie.toArray(trie, func(k, v) = (k, v)); + Trie.toArray(trie, func(k, v) = (k, v)) }; func arrayTest(array : [(Nat, Nat)]) : M.Matcher<[(Nat, Nat)]> { - M.equals<[(Nat, Nat)]>(T.array<(Nat, Nat)>(T.tuple2Testable(T.natTestable, T.natTestable), array)); + M.equals<[(Nat, Nat)]>(T.array<(Nat, Nat)>(T.tuple2Testable(T.natTestable, T.natTestable), array)) }; func natKey(nat : Nat) : Trie.Key { { hash = Hash.hash(nat); key = nat } }; @@ -43,77 +43,77 @@ let suite = Suite.suite( Suite.test( "empty trie size 0", Trie.size(Trie.empty()), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), Suite.test( "empty trie array roundtrip", prettyArray(Trie.empty()), - arrayTest([]), + arrayTest([]) ), Suite.test( "put 1", prettyArray(Trie.put(Trie.empty(), natKey(0), Nat.equal, 10).0), - arrayTest([(0, 10)]), + arrayTest([(0, 10)]) ), Suite.test( "put get 1", Trie.get(Trie.put(Trie.empty(), natKey(0), Nat.equal, 10).0, natKey(0), Nat.equal), - M.equals(T.optional(T.natTestable, ?10)), + M.equals(T.optional(T.natTestable, ?10)) ), Suite.test( "put find 1", Trie.find(Trie.put(Trie.empty(), natKey(0), Nat.equal, 10).0, natKey(0), Nat.equal), - M.equals(T.optional(T.natTestable, ?10)), + M.equals(T.optional(T.natTestable, ?10)) ), Suite.test( "merge", prettyArray(Trie.merge(trie1, trie3, Nat.equal)), - arrayTest([(0, 10), (4, 14), (1, 21), (2, 12)]), + arrayTest([(0, 10), (4, 14), (1, 21), (2, 12)]) ), Suite.test( "merge with empty", prettyArray(Trie.merge(trie1, Trie.empty(), Nat.equal)), - arrayTest([(0, 10), (2, 12), (4, 14)]), + arrayTest([(0, 10), (2, 12), (4, 14)]) ), Suite.test( "merge two empties", prettyArray(Trie.merge(Trie.empty(), Trie.empty(), Nat.equal)), - arrayTest([]), + arrayTest([]) ), Suite.test( "merge disjoint", prettyArray(Trie.mergeDisjoint(trie1, trie2, Nat.equal)), - arrayTest([(0, 10), (2, 12), (4, 14), (1, 11), (3, 13)]), + arrayTest([(0, 10), (2, 12), (4, 14), (1, 11), (3, 13)]) ), Suite.test( "merge disjoint", prettyArray(Trie.mergeDisjoint(trie1, Trie.empty(), Nat.equal)), - arrayTest([(0, 10), (2, 12), (4, 14)]), + arrayTest([(0, 10), (2, 12), (4, 14)]) ), Suite.test( "merge disjoint two empties", prettyArray(Trie.mergeDisjoint(Trie.empty(), Trie.empty(), Nat.equal)), - arrayTest([]), + arrayTest([]) ), Suite.test( "diff", prettyArray(Trie.diff(trie1, trie3, Nat.equal)), - arrayTest([(0, 10), (4, 14)]), + arrayTest([(0, 10), (4, 14)]) ), Suite.test( "diff non-commutative", prettyArray(Trie.diff(trie3, trie1, Nat.equal)), - arrayTest([(1, 21)]), + arrayTest([(1, 21)]) ), Suite.test( "diff empty right", prettyArray(Trie.diff(trie1, Trie.empty(), Nat.equal)), - arrayTest([(0, 10), (2, 12), (4, 14)]), + arrayTest([(0, 10), (2, 12), (4, 14)]) ), Suite.test( "diff empty left", prettyArray(Trie.diff(Trie.empty(), trie1, Nat.equal)), - arrayTest([]), + arrayTest([]) ), Suite.test( "disj", @@ -127,12 +127,12 @@ let suite = Suite.suite( case (?v1, ?v2) v1 + v2; // add values to combine case (?v1, null) v1; case (null, ?v2) v2; - case (null, null) Debug.trap "unreachable in disj"; - }; - }, - ), + case (null, null) Debug.trap "unreachable in disj" + } + } + ) ), - arrayTest([(0, 10), (4, 14), (1, 21), (2, 34)]), + arrayTest([(0, 10), (4, 14), (1, 21), (2, 34)]) ), Suite.test( "disj with empty first", @@ -146,12 +146,12 @@ let suite = Suite.suite( case (?v1, ?v2) v1 + v2; // add values to combine case (?v1, null) v1; case (null, ?v2) v2; - case (null, null) Debug.trap "unreachable in disj"; - }; - }, - ), + case (null, null) Debug.trap "unreachable in disj" + } + } + ) ), - arrayTest([(0, 10), (2, 12), (4, 14)]), + arrayTest([(0, 10), (2, 12), (4, 14)]) ), Suite.test( "disj with empty second", @@ -165,12 +165,12 @@ let suite = Suite.suite( case (?v1, ?v2) v1 + v2; // add values to combine case (?v1, null) v1; case (null, ?v2) v2; - case (null, null) Debug.trap "unreachable in disj"; - }; - }, - ), + case (null, null) Debug.trap "unreachable in disj" + } + } + ) ), - arrayTest([(0, 10), (2, 12), (4, 14)]), + arrayTest([(0, 10), (2, 12), (4, 14)]) ), Suite.test( "disj two empties", @@ -184,155 +184,155 @@ let suite = Suite.suite( case (?v1, ?v2) v1 + v2; // add values to combine case (?v1, null) v1; case (null, ?v2) v2; - case (null, null) Debug.trap "unreachable in disj"; - }; - }, - ), + case (null, null) Debug.trap "unreachable in disj" + } + } + ) ), - arrayTest([]), + arrayTest([]) ), Suite.test( "join", prettyArray( - Trie.join(trie1, trie3, Nat.equal, Nat.add), + Trie.join(trie1, trie3, Nat.equal, Nat.add) ), - arrayTest([(2, 34)]), + arrayTest([(2, 34)]) ), Suite.test( "join with empty first", prettyArray( - Trie.join(Trie.empty(), trie1, Nat.equal, Nat.add), + Trie.join(Trie.empty(), trie1, Nat.equal, Nat.add) ), - arrayTest([]), + arrayTest([]) ), Suite.test( "join with empty second", prettyArray( - Trie.join(trie1, Trie.empty(), Nat.equal, Nat.add), + Trie.join(trie1, Trie.empty(), Nat.equal, Nat.add) ), - arrayTest([]), + arrayTest([]) ), Suite.test( "join with two empties", prettyArray( - Trie.join(Trie.empty(), Trie.empty(), Nat.equal, Nat.add), + Trie.join(Trie.empty(), Trie.empty(), Nat.equal, Nat.add) ), - arrayTest([]), + arrayTest([]) ), Suite.test( "foldUp", Trie.foldUp(trie1, Nat.mul, Nat.add, 1), - M.equals(T.nat(2520)), + M.equals(T.nat(2520)) ), // 1 * (0 + 10) * (2 + 12) * (4 + 14) Suite.test( "foldUp empty", Trie.foldUp(Trie.empty(), Nat.mul, Nat.add, 1), - M.equals(T.nat(1)), + M.equals(T.nat(1)) ), Suite.test( "prod", prettyArray(Trie.prod(trie1, trie3, func(k1, v1, k2, v2) = ?(natKey(k1 + k2), v1 + v2), Nat.equal)), - arrayTest([(1, 31), (2, 32), (3, 33), (4, 34), (5, 35), (6, 36)]), + arrayTest([(1, 31), (2, 32), (3, 33), (4, 34), (5, 35), (6, 36)]) ), Suite.test( "prod first empty", prettyArray(Trie.prod(Trie.empty(), trie3, func(k1, v1, k2, v2) = ?(natKey(k1 + k2), v1 + v2), Nat.equal)), - arrayTest([]), + arrayTest([]) ), Suite.test( "prod second empty", prettyArray(Trie.prod(trie1, Trie.empty(), func(k1, v1, k2, v2) = ?(natKey(k1 + k2), v1 + v2), Nat.equal)), - arrayTest([]), + arrayTest([]) ), Suite.test( "prod both empty", prettyArray(Trie.prod(Trie.empty(), Trie.empty(), func(k1, v1, k2, v2) = ?(natKey(k1 + k2), v1 + v2), Nat.equal)), - arrayTest([]), + arrayTest([]) ), Suite.test( "iter", Iter.toArray(Trie.iter(trie1)), - arrayTest([(0, 10), (2, 12), (4, 14)]), + arrayTest([(0, 10), (2, 12), (4, 14)]) ), Suite.test( "iter empty", Iter.toArray(Trie.iter(Trie.empty())), - arrayTest([]), + arrayTest([]) ), Suite.test( "fold", Trie.fold(trie1, func(k, v, acc) = k + v + acc, 0), - M.equals(T.nat(42)), + M.equals(T.nat(42)) ), // 0 + 10 + 2 + 12 + 4 + 14 Suite.test( "fold empty", Trie.fold(Trie.empty(), func(k, v, acc) = k + v + acc, 0), - M.equals(T.nat(0)), + M.equals(T.nat(0)) ), Suite.test( "some true", Trie.some(trie1, func(k, v) = k * v == 0), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), Suite.test( "some false", Trie.some(trie1, func(k, _) = k % 2 != 0), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), Suite.test( "some empty", Trie.some(Trie.empty(), func _ = true), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), Suite.test( "all true", Trie.all(trie1, func(k, _) = k % 2 == 0), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), Suite.test( "all false", Trie.all(trie1, func(k, v) = k * v == 0), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), Suite.test( "all empty", Trie.all(Trie.empty(), func _ = false), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), // FIXME test nth Suite.test( "isEmpty false", Trie.isEmpty(trie1), - M.equals(T.bool(false)), + M.equals(T.bool(false)) ), Suite.test( "isEmpty true", Trie.isEmpty(Trie.empty()), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), Suite.test( "isEmpty put remove", Trie.isEmpty( - Trie.remove(Trie.put(Trie.empty(), natKey(0), Nat.equal, 10).0, natKey(0), Nat.equal).0, + Trie.remove(Trie.put(Trie.empty(), natKey(0), Nat.equal, 10).0, natKey(0), Nat.equal).0 ), - M.equals(T.bool(true)), + M.equals(T.bool(true)) ), Suite.test( "filter", prettyArray(Trie.filter(trie1, func(k, v) = k * v == 0)), - arrayTest([(0, 10)]), + arrayTest([(0, 10)]) ), Suite.test( "filter all", prettyArray(Trie.filter(trie1, func _ = false)), - arrayTest([]), + arrayTest([]) ), Suite.test( "filter none", prettyArray(Trie.filter(trie1, func _ = true)), - arrayTest([(0, 10), (2, 12), (4, 14)]), - ), - ], + arrayTest([(0, 10), (2, 12), (4, 14)]) + ) + ] ); // FIXME add tests for bitpos functions @@ -347,7 +347,7 @@ debug { func key(i : Nat) : Key { let t = Nat.toText i; - { key = t; hash = Text.hash t }; + { key = t; hash = Text.hash t } }; let max = 100; @@ -359,7 +359,7 @@ debug { let (t1_, x) = Trie.put(t, key i, Text.equal, i); assert (Option.isNull(x)); assert Trie.isValid(t1_, false); - t := t1_; + t := t1_ }; assert Trie.size(t) == max; @@ -371,8 +371,8 @@ debug { let (t1_, x) = Trie.remove(t1, key i, Text.equal); assert Trie.isValid(t1_, false); assert (Option.isSome(x)); - t1 := t1_; - }; + t1 := t1_ + } }; // filter all elements away, one by one (but hashes are expected random). @@ -382,8 +382,8 @@ debug { for (i in Iter.range(0, max - 1)) { t1 := Trie.filter(t1, func(t : Text, n : Nat) : Bool { n != i }); assert Trie.isValid(t1, false); - assert Trie.size(t1) == (max - (i + 1) : Nat); - }; + assert Trie.size(t1) == (max - (i + 1) : Nat) + } }; // filter-map all elements away, one by one (but hashes are expected random). @@ -394,11 +394,11 @@ debug { t1 := Trie.mapFilter( t1, func(t : Text, n : Nat) : ?Nat { - if (n != i) ?n else null; - }, + if (n != i) ?n else null + } ); assert Trie.isValid(t1, false); - assert Trie.size(t1) == (max - (i + 1) : Nat); - }; - }; -}; + assert Trie.size(t1) == (max - (i + 1) : Nat) + } + } +}