fix #654 by having assert-eq accept a vase of a pair

flipping the order of the pair while rewriting all the test was necessary anyawy, to accoutn for heavier-twig tendencies
This commit is contained in:
Anton Dyudin 2018-03-09 19:25:29 -08:00
parent 3bb24f1327
commit d0138ff7fa
6 changed files with 397 additions and 397 deletions

View File

@ -137,12 +137,13 @@
+| +|
:: todo: unit testing libraries have a lot more to them than just eq. :: todo: unit testing libraries have a lot more to them than just eq.
++ expect-eq ++ expect-eq
|* [a=* b=*] |= a=vase
^- wall ^- wall
?: =(a b) ?@ q.a ["ex-expected-pair: '{(text a)}'"]~
?: =(-.q.a +.q.a)
~ ~
:~ "actual: '{(noah !>(a))}'" :~ "expected: '{(text (slot 2 a))}'"
"expected: '{(noah !>(b))}'" "actual: '{(text (slot 3 a))}'"
== ==
:> # :> #
:> # %formatting :> # %formatting

View File

@ -2,241 +2,241 @@
=, ls:new-hoon =, ls:new-hoon
|_ _tester:tester |_ _tester:tester
++ test-head ++ test-head
(expect-eq (head [1 ~]) 1) (expect-eq !>([1 (head [1 ~])]))
:: ::
++ test-last ++ test-last
(expect-eq (last:ls [1 2 ~]) 2) (expect-eq !>([2 (last:ls [1 2 ~])]))
:: ::
++ test-tail ++ test-tail
(expect-eq (tail [1 2 3 ~]) [2 3 ~]) (expect-eq !>([[2 3 ~] (tail [1 2 3 ~])]))
:: ::
++ test-init ++ test-init
(expect-eq (init [1 2 3 ~]) [1 2 ~]) (expect-eq !>([[1 2 ~] (init [1 2 3 ~])]))
:: ::
++ test-size ++ test-size
(expect-eq (size ['a' 'b' 'c' ~]) 3) (expect-eq !>([3 (size ['a' 'b' 'c' ~])]))
:: ::
++ test-map ++ test-map
(expect-eq (map:ls [1 2 ~] |=(a/@ (add 1 a))) [2 3 ~]) (expect-eq !>([[2 3 ~] (map:ls [1 2 ~] |=(a/@ (add 1 a)))]))
:: ::
++ test-reverse ++ test-reverse
(expect-eq (reverse [1 2 3 ~]) [3 2 1 ~]) (expect-eq !>([[3 2 1 ~] (reverse [1 2 3 ~])]))
:: ::
++ test-intersperse ++ test-intersperse
(expect-eq (intersperse 1 [5 5 5 ~]) [5 1 5 1 5 ~]) (expect-eq !>([[5 1 5 1 5 ~] (intersperse 1 [5 5 5 ~])]))
:: ::
++ test-intercalate ++ test-intercalate
%+ expect-eq %- expect-eq !>
(intercalate "," ["one" "two" "three" ~]) :- ["one,two,three"]
["one,two,three"] (intercalate "," ["one" "two" "three" ~])
:: ::
++ test-transpose ++ test-transpose
%+ expect-eq %- expect-eq !>
(transpose ~[~[1 2 3] ~[4 5 6]]) :- ~[~[1 4] ~[2 5] ~[3 6]]
~[~[1 4] ~[2 5] ~[3 6]] (transpose ~[~[1 2 3] ~[4 5 6]])
:: ::
++ test-foldl ++ test-foldl
(expect-eq (foldl [1 2 3 ~] 3 |=({a/@ b/@} (add a b))) 9) (expect-eq !>([9 (foldl [1 2 3 ~] 3 |=({a/@ b/@} (add a b)))]))
:: ::
++ test-foldr ++ test-foldr
(expect-eq (foldr [1 2 3 ~] 1 |=({a/@ b/@} (add a b))) 7) (expect-eq !>([7 (foldr [1 2 3 ~] 1 |=({a/@ b/@} (add a b)))]))
:: ::
++ test-concat ++ test-concat
(expect-eq (concat ~[~[1 2] ~[3 4]]) ~[1 2 3 4]) (expect-eq !>([~[1 2 3 4] (concat ~[~[1 2] ~[3 4]])]))
:: ::
++ test-weld ++ test-weld
(expect-eq (weld:ls ~[1 2 3] ~["one" "two"]) ~[1 2 3 "one" "two"]) (expect-eq !>([~[1 2 3 "one" "two"] (weld:ls ~[1 2 3] ~["one" "two"])]))
:: ::
++ test-any-true ++ test-any-true
(expect-eq (any [1 2 3 ~] |=(a/@ =(a 2))) %.y) (expect-eq !>([%.y (any [1 2 3 ~] |=(a/@ =(a 2)))]))
:: ::
++ test-any-false ++ test-any-false
(expect-eq (any [1 2 3 ~] |=(a/@ =(a 8))) %.n) (expect-eq !>([%.n (any [1 2 3 ~] |=(a/@ =(a 8)))]))
:: ::
++ test-all-true ++ test-all-true
(expect-eq (all [1 1 1 ~] |=(a/@ =(a 1))) %.y) (expect-eq !>([%.y (all [1 1 1 ~] |=(a/@ =(a 1)))]))
:: ::
++ test-all-false ++ test-all-false
(expect-eq (all [1 3 1 ~] |=(a/@ =(a 1))) %.n) (expect-eq !>([%.n (all [1 3 1 ~] |=(a/@ =(a 1)))]))
:: ::
++ test-scanl ++ test-scanl
%+ expect-eq %- expect-eq !>
(scanl ~[1 2 3] 0 |=({a/@ b/@} (add a b))) :- ~[0 1 3 6]
~[0 1 3 6] (scanl ~[1 2 3] 0 |=({a/@ b/@} (add a b)))
:: ::
++ test-scanl1 ++ test-scanl1
%+ expect-eq %- expect-eq !>
(scanl1 ~[1 2 3] |=({a/@ b/@} (add a b))) :- ~[1 3 6]
~[1 3 6] (scanl1 ~[1 2 3] |=({a/@ b/@} (add a b)))
:: ::
++ test-scanr ++ test-scanr
%+ expect-eq %- expect-eq !>
(scanr ~[1 2 3] 0 |=({a/@ b/@} (add a b))) :- ~[6 5 3 0]
~[6 5 3 0] (scanr ~[1 2 3] 0 |=({a/@ b/@} (add a b)))
:: ::
++ test-scanr1 ++ test-scanr1
%+ expect-eq %- expect-eq !>
(scanr1 ~[1 2 3] |=({a/@ b/@} (add a b))) :- ~[6 5 3]
~[6 5 3] (scanr1 ~[1 2 3] |=({a/@ b/@} (add a b)))
:: ::
++ test-map-foldl ++ test-map-foldl
%+ expect-eq %- expect-eq !>
(map-foldl ~[1 2 3] 1 |=({a/@ b/@} [(add a b) (add 1 a)])) :- [7 ~[2 3 5]]
[7 ~[2 3 5]] (map-foldl ~[1 2 3] 1 |=({a/@ b/@} [(add a b) (add 1 a)]))
:: ::
++ test-map-foldr ++ test-map-foldr
%+ expect-eq %- expect-eq !>
(map-foldr ~[1 2 3] 1 |=({a/@ b/@} [(add a b) (add 1 a)])) :- [7 ~[7 5 2]]
[7 ~[7 5 2]] (map-foldr ~[1 2 3] 1 |=({a/@ b/@} [(add a b) (add 1 a)]))
:: ::
++ test-unfoldr ++ test-unfoldr
%+ expect-eq %- expect-eq !>
(unfoldr 5 |=(a/@ ?:(=(a 0) ~ `[a (dec a)]))) :- [5 4 3 2 1 ~]
[5 4 3 2 1 ~] (unfoldr 5 |=(a/@ ?:(=(a 0) ~ `[a (dec a)])))
:: ::
++ test-take ++ test-take
%+ expect-eq %- expect-eq !>
(take 3 ~[1 2 3 4 5]) :- [1 2 3 ~]
[1 2 3 ~] (take 3 ~[1 2 3 4 5])
:: ::
++ test-drop ++ test-drop
%+ expect-eq %- expect-eq !>
(drop:ls 3 ~[1 2 3 4 5]) :- [4 5 ~]
[4 5 ~] (drop:ls 3 ~[1 2 3 4 5])
:: ::
++ test-split-at ++ test-split-at
%+ expect-eq %- expect-eq !>
(split-at 3 ~[1 2 3 4 5]) :- [[1 2 3 ~] [4 5 ~]]
[[1 2 3 ~] [4 5 ~]] (split-at 3 ~[1 2 3 4 5])
:: ::
++ test-take-while ++ test-take-while
%+ expect-eq %- expect-eq !>
(take-while ~[1 2 3 4 5] |=(a/@ (lth a 3))) :- [1 2 ~]
[1 2 ~] (take-while ~[1 2 3 4 5] |=(a/@ (lth a 3)))
:: ::
++ test-drop-while ++ test-drop-while
%+ expect-eq %- expect-eq !>
(drop-while ~[1 2 3 4 5] |=(a/@ (lth a 3))) :- [3 4 5 ~]
[3 4 5 ~] (drop-while ~[1 2 3 4 5] |=(a/@ (lth a 3)))
:: ::
++ test-drop-while-end ++ test-drop-while-end
%+ expect-eq %- expect-eq !>
(drop-while-end ~[5 5 1 5 5] |=(a/@ =(a 5))) :- [5 5 1 ~]
[5 5 1 ~] (drop-while-end ~[5 5 1 5 5] |=(a/@ =(a 5)))
:: ::
++ test-split-on ++ test-split-on
%+ expect-eq %- expect-eq !>
(split-on ~[1 2 3 4 1 2 3 4] |=(a/@ (lth a 3))) :- [[1 2 ~] [3 4 1 2 3 4 ~]]
[[1 2 ~] [3 4 1 2 3 4 ~]] (split-on ~[1 2 3 4 1 2 3 4] |=(a/@ (lth a 3)))
:: ::
++ test-break ++ test-break
%+ expect-eq %- expect-eq !>
(break ~[1 2 3 4 1 2 3 4] |=(a/@ (gth a 3))) :- [[1 2 3 ~] [4 1 2 3 4 ~]]
[[1 2 3 ~] [4 1 2 3 4 ~]] (break ~[1 2 3 4 1 2 3 4] |=(a/@ (gth a 3)))
:: ::
++ test-strip-prefix ++ test-strip-prefix
%+ expect-eq %- expect-eq !>
(strip-prefix "foo" "foobar") :- [~ "bar"]
[~ "bar"] (strip-prefix "foo" "foobar")
:: ::
++ test-inits ++ test-inits
%+ expect-eq %- expect-eq !>
(inits "abc") :- ["a" "ab" "abc" ~]
["a" "ab" "abc" ~] (inits "abc")
:: ::
++ test-tails ++ test-tails
%+ expect-eq %- expect-eq !>
(tails "abc") :- ["abc" "bc" "c" ~]
["abc" "bc" "c" ~] (tails "abc")
:: ::
++ test-is-prefix-of ++ test-is-prefix-of
%+ expect-eq %- expect-eq !>
(is-prefix-of "foo" "foobar") :- %.y
%.y (is-prefix-of "foo" "foobar")
:: ::
++ test-is-suffix-of ++ test-is-suffix-of
%+ expect-eq %- expect-eq !>
(is-suffix-of "bar" "foobar") :- %.y
%.y (is-suffix-of "bar" "foobar")
:: ::
++ test-is-infix-of ++ test-is-infix-of
%+ expect-eq %- expect-eq !>
(is-infix-of "ob" "foobar") :- %.y
%.y (is-infix-of "ob" "foobar")
:: ::
++ test-elem ++ test-elem
%+ expect-eq %- expect-eq !>
(elem 5 [1 2 3 4 5 ~]) :- %.y
%.y (elem 5 [1 2 3 4 5 ~])
:: ::
++ test-lookup ++ test-lookup
%+ expect-eq %- expect-eq !>
(lookup "two" [["one" 1] ["two" 2] ["three" 3] ~]) :- [~ 2]
[~ 2] (lookup "two" [["one" 1] ["two" 2] ["three" 3] ~])
:: ::
++ test-find ++ test-find
%+ expect-eq %- expect-eq !>
(find:ls [3 2 1 5 1 2 3 ~] |=(a/@ (gth a 3))) :- [~ 5]
[~ 5] (find:ls [3 2 1 5 1 2 3 ~] |=(a/@ (gth a 3)))
:: ::
++ test-filter ++ test-filter
%+ expect-eq %- expect-eq !>
(filter [1 2 1 2 1 ~] |=(a/@ =(a 2))) :- [1 1 1 ~]
[1 1 1 ~] (filter [1 2 1 2 1 ~] |=(a/@ =(a 2)))
:: ::
++ test-partition ++ test-partition
%+ expect-eq %- expect-eq !>
(partition [1 2 1 2 1 ~] |=(a/@ =(a 2))) :- [[2 2 ~] [1 1 1 ~]]
[[2 2 ~] [1 1 1 ~]] (partition [1 2 1 2 1 ~] |=(a/@ =(a 2)))
:: ::
++ test-elem-index ++ test-elem-index
%+ expect-eq %- expect-eq !>
(elem-index 2 [1 2 3 4 ~]) :- `1
`1 (elem-index 2 [1 2 3 4 ~])
:: ::
++ test-elem-indices ++ test-elem-indices
%+ expect-eq %- expect-eq !>
(elem-indices 2 [1 2 1 2 ~]) :- [1 3 ~]
[1 3 ~] (elem-indices 2 [1 2 1 2 ~])
:: ::
++ test-find-index ++ test-find-index
%+ expect-eq %- expect-eq !>
(find-index [1 2 3 ~] |=(a/@ =(a 2))) :- `1
`1 (find-index [1 2 3 ~] |=(a/@ =(a 2)))
:: ::
++ test-find-indices ++ test-find-indices
%+ expect-eq %- expect-eq !>
(find-indices [1 2 1 2 ~] |=(a/@ =(a 2))) :- [1 3 ~]
[1 3 ~] (find-indices [1 2 1 2 ~] |=(a/@ =(a 2)))
:: ::
++ test-zip ++ test-zip
%+ expect-eq %- expect-eq !>
(zip [[1 2 3 ~] [4 5 6 ~] [7 8 9 ~] ~]) :- [[1 4 7 ~] [2 5 8 ~] [3 6 9 ~] ~]
[[1 4 7 ~] [2 5 8 ~] [3 6 9 ~] ~] (zip [[1 2 3 ~] [4 5 6 ~] [7 8 9 ~] ~])
:: ::
++ test-unique ++ test-unique
%+ expect-eq %- expect-eq !>
(unique [1 2 3 1 2 3 ~]) :- [1 2 3 ~]
[1 2 3 ~] (unique [1 2 3 1 2 3 ~])
:: ::
++ test-delete ++ test-delete
%+ expect-eq %- expect-eq !>
(delete 2 [1 2 3 2 ~]) :- [1 3 2 ~]
[1 3 2 ~] (delete 2 [1 2 3 2 ~])
:: ::
++ test-delete-firsts ++ test-delete-firsts
%+ expect-eq %- expect-eq !>
(delete-firsts [1 2 2 2 3 4 5 ~] [2 2 5 ~]) :- [1 2 3 4 ~]
[1 2 3 4 ~] (delete-firsts [1 2 2 2 3 4 5 ~] [2 2 5 ~])
:: ::
++ test-union ++ test-union
%+ expect-eq %- expect-eq !>
(union [1 2 3 ~] [4 2 5 ~]) :- [1 2 3 4 5 ~]
[1 2 3 4 5 ~] (union [1 2 3 ~] [4 2 5 ~])
:: ::
++ test-intersect ++ test-intersect
%+ expect-eq %- expect-eq !>
(intersect [5 6 6 7 8 ~] [9 8 8 6 ~]) :- [6 6 8 ~]
[6 6 8 ~] (intersect [5 6 6 7 8 ~] [9 8 8 6 ~])
-- --

View File

@ -4,87 +4,86 @@
=+ three=(from-list [[1 "one"] [2 "two"] [3 "three"] ~]) =+ three=(from-list [[1 "one"] [2 "two"] [3 "three"] ~])
|_ _tester:tester |_ _tester:tester
++ test-empty ++ test-empty
(expect-eq (empty four) %.n) (expect-eq !>([%.n (empty four)]))
:: ::
++ test-size ++ test-size
(expect-eq (size four) 4) (expect-eq !>([4 (size four)]))
:: ::
++ test-member ++ test-member
(expect-eq (member four 4) %.y) (expect-eq !>([%.y (member four 4)]))
:: ::
++ test-put-with ++ test-put-with
=+ ints=(from-list [["one" 1] ["two" 2] ["three" 3] ["four" 4] ~]) %- expect-eq !>
%+ expect-eq :- (from-list [["one" 1] ["two" 2] ["three" 5] ["four" 4] ~])
(put-with ints "three" 2 add) =/ ints (from-list [["one" 1] ["two" 2] ["three" 3] ["four" 4] ~])
(from-list [["one" 1] ["two" 2] ["three" 5] ["four" 4] ~]) (put-with ints "three" 2 add)
:: ::
++ test-put-with-key ++ test-put-with-key
%+ expect-eq %- expect-eq !>
(put-with-key four 4 "four" |=({a/@ud b/tape c/tape} (weld (scow %ud a) b))) :- (from-list [[1 "one"] [2 "two"] [3 "three"] [4 "4four"] ~])
(from-list [[1 "one"] [2 "two"] [3 "three"] [4 "4four"] ~]) (put-with-key four 4 "four" |=({a/@ud b/tape c/tape} (weld (scow %ud a) b)))
:: ::
++ test-put-lookup-with-key ++ test-put-lookup-with-key
%+ expect-eq %- expect-eq !>
%^ put-lookup-with-key four :- [`"four" (from-list [[1 "one"] [2 "two"] [3 "three"] [4 "five"] ~])]
4 %^ put-lookup-with-key four
:- "five" 4
|=({key/@ud old/tape new/tape} new) :- "five"
:- `"four" |=({key/@ud old/tape new/tape} new)
(from-list [[1 "one"] [2 "two"] [3 "three"] [4 "five"] ~])
:: ::
++ test-delete ++ test-delete
%+ expect-eq %- expect-eq !>
(delete four 4) :- three
three (delete four 4)
:: ::
++ test-adjust ++ test-adjust
%+ expect-eq %- expect-eq !>
%^ adjust four :- (from-list [[1 "one"] [2 "two"] [3 "thisthree"] [4 "four"] ~])
3 %^ adjust four
|=(a/tape (weld "this" a)) 3
(from-list [[1 "one"] [2 "two"] [3 "thisthree"] [4 "four"] ~]) |=(a/tape (weld "this" a))
:: ::
++ test-adjust-with-key ++ test-adjust-with-key
%+ expect-eq %- expect-eq !>
%^ adjust-with-key four :- (from-list [[1 "one"] [2 "two"] [3 "3three"] [4 "four"] ~])
3 %^ adjust-with-key four
|=({a/@ud b/tape} (weld (scow %ud a) b)) 3
(from-list [[1 "one"] [2 "two"] [3 "3three"] [4 "four"] ~]) |=({a/@ud b/tape} (weld (scow %ud a) b))
:: ::
++ test-update ++ test-update
%+ expect-eq %- expect-eq !>
%^ update four :- (from-list [[1 "one"] [2 "two"] [4 "four"] ~])
3 %^ update four
|=(a/tape `(maybe tape)`~) 3
(from-list [[1 "one"] [2 "two"] [4 "four"] ~]) |=(a/tape `(maybe tape)`~)
:: ::
++ test-update-with-key ++ test-update-with-key
%+ expect-eq %- expect-eq !>
%^ update-with-key four :- (from-list [[1 "one"] [2 "two"] [3 "3three"] [4 "four"] ~])
3 %^ update-with-key four
|=({a/@u b/tape} `(maybe tape)`[~ (weld (scow %ud a) b)]) 3
(from-list [[1 "one"] [2 "two"] [3 "3three"] [4 "four"] ~]) |=({a/@u b/tape} `(maybe tape)`[~ (weld (scow %ud a) b)])
:: ::
++ test-alter-as-add ++ test-alter-as-add
%+ expect-eq %- expect-eq !>
%^ alter four :- (from-list [[1 "one"] [2 "two"] [3 "three"] [4 "four"] [5 "five"] ~])
5 %^ alter four
|=(a/(maybe tape) `(maybe tape)`[~ "five"]) 5
(from-list [[1 "one"] [2 "two"] [3 "three"] [4 "four"] [5 "five"] ~]) |=(a/(maybe tape) `(maybe tape)`[~ "five"])
:: ::
++ test-alter-as-delete ++ test-alter-as-delete
%+ expect-eq %- expect-eq !>
%^ alter four :- (from-list [[1 "one"] [3 "three"] [4 "four"] ~])
2 %^ alter four
|=(a/(maybe tape) `(maybe tape)`~) 2
(from-list [[1 "one"] [3 "three"] [4 "four"] ~]) |=(a/(maybe tape) `(maybe tape)`~)
:: ::
++ test-alter-as-change ++ test-alter-as-change
%+ expect-eq %- expect-eq !>
%^ alter four :- (from-list [[1 "one"] [2 "dos"] [3 "three"] [4 "four"] ~])
2 %^ alter four
|=(a/(maybe tape) `(maybe tape)`[~ "dos"]) 2
(from-list [[1 "one"] [2 "dos"] [3 "three"] [4 "four"] ~]) |=(a/(maybe tape) `(maybe tape)`[~ "dos"])
:: ::
++ check-alter ++ check-alter
:: check random dicts of 50 items with 40 random operations done on them :: check random dicts of 50 items with 40 random operations done on them
@ -114,192 +113,192 @@
$(i +(i)) $(i +(i))
:: ::
++ test-union ++ test-union
%+ expect-eq %- expect-eq !>
%+ union :- (from-list [[1 "left"] [2 "left"] [3 "right"] ~])
(from-list [[1 "left"] [2 "left"] ~]) %+ union
(from-list [[2 "right"] [3 "right"] ~]) (from-list [[1 "left"] [2 "left"] ~])
(from-list [[1 "left"] [2 "left"] [3 "right"] ~]) (from-list [[2 "right"] [3 "right"] ~])
:: ::
++ test-union-with ++ test-union-with
%+ expect-eq %- expect-eq !>
%^ union-with :- (from-list [[1 "left"] [2 "leftright"] [3 "right"] ~])
(from-list [[1 "left"] [2 "left"] ~]) %^ union-with
(from-list [[2 "right"] [3 "right"] ~]) (from-list [[1 "left"] [2 "left"] ~])
|=({a/tape b/tape} (weld a b)) (from-list [[2 "right"] [3 "right"] ~])
(from-list [[1 "left"] [2 "leftright"] [3 "right"] ~]) |=({a/tape b/tape} (weld a b))
:: ::
++ test-union-with-key ++ test-union-with-key
%+ expect-eq %- expect-eq !>
%^ union-with-key :- (from-list [[1 "left"] [2 "2leftright"] [3 "right"] ~])
(from-list [[1 "left"] [2 "left"] ~]) %^ union-with-key
(from-list [[2 "right"] [3 "right"] ~]) (from-list [[1 "left"] [2 "left"] ~])
|=({a/@ud b/tape c/tape} :(weld `tape`(scow %ud a) b c)) (from-list [[2 "right"] [3 "right"] ~])
(from-list [[1 "left"] [2 "2leftright"] [3 "right"] ~]) |=({a/@ud b/tape c/tape} :(weld `tape`(scow %ud a) b c))
:: ::
++ test-map ++ test-map
%+ expect-eq %- expect-eq !>
(map:dct three crip) :- (from-list [[1 'one'] [2 'two'] [3 'three'] ~])
(from-list [[1 'one'] [2 'two'] [3 'three'] ~]) (map:dct three crip)
:: ::
++ test-map-with-key ++ test-map-with-key
%+ expect-eq %- expect-eq !>
%+ map-with-key three :- (from-list [[1 "1one"] [2 "2two"] [3 "3three"] ~])
|=({a/@u b/tape} (weld (scow %ud a) b)) %+ map-with-key three
(from-list [[1 "1one"] [2 "2two"] [3 "3three"] ~]) |=({a/@u b/tape} (weld (scow %ud a) b))
:: ::
++ test-map-fold ++ test-map-fold
%+ expect-eq %- expect-eq !>
%^ map-fold three :- :- "Everything: two one three"
"Everything:" (from-list [[1 "oneX"] [2 "twoX"] [3 "threeX"] ~])
|= {accumulator/tape value/tape} %^ map-fold three
[:(weld accumulator " " value) (weld value "X")] "Everything:"
:- "Everything: two one three" |= {accumulator/tape value/tape}
(from-list [[1 "oneX"] [2 "twoX"] [3 "threeX"] ~]) [:(weld accumulator " " value) (weld value "X")]
:: ::
++ test-map-keys ++ test-map-keys
%+ expect-eq %- expect-eq !>
%+ map-keys three :- (from-list [[11 "one"] [12 "two"] [13 "three"] ~])
|=(a/@u (add a 10)) %+ map-keys three
(from-list [[11 "one"] [12 "two"] [13 "three"] ~]) |=(a/@u (add a 10))
:: ::
++ test-map-keys-with ++ test-map-keys-with
%+ expect-eq %- expect-eq !>
%^ map-keys-with three :- (from-list [[42 "twothreeone"] ~])
|=(a/@u 42) %^ map-keys-with three
weld |=(a/@u 42)
(from-list [[42 "twothreeone"] ~]) weld
:: ::
++ test-fold ++ test-fold
%+ expect-eq %- expect-eq !>
%^ fold three :- "Everything: twoonethree"
"Everything: " %^ fold three
:: todo: this works but replacing with just ++weld causes an out of loom. "Everything: "
|= {accumulator/tape value/tape} :: todo: this works but replacing with just ++weld causes an out of loom.
^- tape |= {accumulator/tape value/tape}
(weld accumulator value) ^- tape
"Everything: twoonethree" (weld accumulator value)
:: ::
++ test-fold-with-keys ++ test-fold-with-keys
%+ expect-eq %- expect-eq !>
%^ fold-with-keys three :- "Everything: 2two1one3three"
"Everything: " %^ fold-with-keys three
|= {accumulator/tape key/@u value/tape} "Everything: "
^- tape |= {accumulator/tape key/@u value/tape}
:(weld accumulator (scow %ud key) value) ^- tape
"Everything: 2two1one3three" :(weld accumulator (scow %ud key) value)
:: ::
++ test-elems ++ test-elems
%+ expect-eq %- expect-eq !>
(elems three) :- ["two" "three" "one" ~]
["two" "three" "one" ~] (elems three)
:: ::
++ test-keys ++ test-keys
%+ expect-eq %- expect-eq !>
(keys three) :- [2 3 1 ~]
[2 3 1 ~] (keys three)
:: ::
++ test-keys-set ++ test-keys-set
%+ expect-eq %- expect-eq !>
(keys-set three) :- (si:nl [2 3 1 ~])
(si:nl [2 3 1 ~]) (keys-set three)
:: ::
++ test-from-set ++ test-from-set
%+ expect-eq %- expect-eq !>
%+ from-set :- (from-list [[1 "1"] [2 "2"] [3 "3"] ~])
(si:nl [1 2 3 ~]) %+ from-set
|=(a/@u (scow %ud a)) (si:nl [1 2 3 ~])
(from-list [[1 "1"] [2 "2"] [3 "3"] ~]) |=(a/@u (scow %ud a))
:: ::
++ test-from-list-with ++ test-from-list-with
%+ expect-eq %- expect-eq !>
%+ from-list-with :- (from-list [[1 1] [2 2] [3 3] ~])
[[1 1] [2 1] [2 1] [3 3] ~] %+ from-list-with
add [[1 1] [2 1] [2 1] [3 3] ~]
(from-list [[1 1] [2 2] [3 3] ~]) add
:: ::
++ test-filter ++ test-filter
%+ expect-eq %- expect-eq !>
%+ filter :- (from-list [[1 1] [2 1] [4 1] ~])
(from-list [[1 1] [2 1] [3 2] [4 1] ~]) %+ filter
|=(a/@u !=(a 1)) (from-list [[1 1] [2 1] [3 2] [4 1] ~])
(from-list [[1 1] [2 1] [4 1] ~]) |=(a/@u !=(a 1))
:: ::
++ test-filter-with-key ++ test-filter-with-key
%+ expect-eq %- expect-eq !>
%+ filter-with-key :- (from-list [[1 1] [3 2] [4 1] ~])
(from-list [[1 1] [2 1] [3 2] [4 1] ~]) %+ filter-with-key
|=({a/@u b/@u} =(a 2)) (from-list [[1 1] [2 1] [3 2] [4 1] ~])
(from-list [[1 1] [3 2] [4 1] ~]) |=({a/@u b/@u} =(a 2))
:: ::
++ test-restrict-keys ++ test-restrict-keys
%+ expect-eq %- expect-eq !>
%+ restrict-keys :- (from-list [[1 1] [3 3] [5 5] ~])
(from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~]) %+ restrict-keys
(si:nl [1 3 5 ~]) (from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~])
(from-list [[1 1] [3 3] [5 5] ~]) (si:nl [1 3 5 ~])
:: ::
++ test-without-keys ++ test-without-keys
%+ expect-eq %- expect-eq !>
%+ without-keys :- (from-list [[2 2] [4 4] ~])
(from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~]) %+ without-keys
(si:nl [1 3 5 ~]) (from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~])
(from-list [[2 2] [4 4] ~]) (si:nl [1 3 5 ~])
:: ::
++ test-partition ++ test-partition
%+ expect-eq %- expect-eq !>
%+ partition :- :- (from-list [[1 1] [3 3] ~])
(from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~]) (from-list [[2 2] [4 4] [5 5] ~])
|=(a/@u |(=(a 1) =(a 3))) %+ partition
:- (from-list [[1 1] [3 3] ~]) (from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~])
(from-list [[2 2] [4 4] [5 5] ~]) |=(a/@u |(=(a 1) =(a 3)))
:: ::
++ test-map-maybe ++ test-map-maybe
%+ expect-eq %- expect-eq !>
%+ map-maybe :- (from-list [[1 1] [2 2] [4 4] [5 5] ~])
(from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~]) %+ map-maybe
|=(a/@u ?:(=(a 3) ~ `a)) (from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~])
(from-list [[1 1] [2 2] [4 4] [5 5] ~]) |=(a/@u ?:(=(a 3) ~ `a))
:: ::
++ test-map-maybe-with-key ++ test-map-maybe-with-key
%+ expect-eq %- expect-eq !>
%+ map-maybe-with-key :- (from-list [[1 2] [2 3] [4 5] [5 6] ~])
(from-list [[1 2] [2 3] [3 4] [4 5] [5 6] ~]) %+ map-maybe-with-key
|=({k/@u v/@u} ?:(=(k 3) ~ `v)) (from-list [[1 2] [2 3] [3 4] [4 5] [5 6] ~])
(from-list [[1 2] [2 3] [4 5] [5 6] ~]) |=({k/@u v/@u} ?:(=(k 3) ~ `v))
:: ::
++ test-map-either ++ test-map-either
%+ expect-eq %- expect-eq !>
%+ map-either :- :- (from-list [[2 "even"] [4 "even"] ~])
(from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~]) (from-list [[1 1] [3 1] [5 1] ~])
|= value/@u %+ map-either
?: =(0 (mod value 2)) (from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~])
[%& "even"] |= value/@u
[%| 1] ?: =(0 (mod value 2))
:- (from-list [[2 "even"] [4 "even"] ~])
(from-list [[1 1] [3 1] [5 1] ~])
::
++ test-map-either-with-key
%+ expect-eq
%+ map-either-with-key
(from-list [[1 1] [2 1] [3 1] [4 1] [5 1] ~])
|= {key/@u value/@u}
?: =(0 (mod key 2))
[%& "even"] [%& "even"]
[%| 1] [%| 1]
:- (from-list [[2 "even"] [4 "even"] ~]) ::
(from-list [[1 1] [3 1] [5 1] ~]) ++ test-map-either-with-key
%- expect-eq !>
:- :- (from-list [[2 "even"] [4 "even"] ~])
(from-list [[1 1] [3 1] [5 1] ~])
%+ map-either-with-key
(from-list [[1 1] [2 1] [3 1] [4 1] [5 1] ~])
|= {key/@u value/@u}
?: =(0 (mod key 2))
[%& "even"]
[%| 1]
:: ::
++ test-is-subdict ++ test-is-subdict
%+ expect-eq %- expect-eq !>
%^ is-subdict-by :- &
(from-list [[1 1] [4 4] ~]) %^ is-subdict-by
(from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~]) (from-list [[1 1] [4 4] ~])
|=({a/* b/*} =(a b)) (from-list [[1 1] [2 2] [3 3] [4 4] [5 5] ~])
%.y |=({a/* b/*} =(a b))
:: ::
++ test-valid ++ test-valid
%+ expect-eq %- expect-eq !>
(valid (from-list [[1 1] [2 2] [3 3] [4 4] [5 5] [6 6] [7 7] [8 8] [9 9] ~])) :- &
%.y (valid (from-list [[1 1] [2 2] [3 3] [4 4] [5 5] [6 6] [7 7] [8 8] [9 9] ~]))
-- --

View File

@ -2,30 +2,30 @@
=, myb:new-hoon =, myb:new-hoon
|_ _tester:tester |_ _tester:tester
++ test-from-list-null ++ test-from-list-null
(expect-eq (from-list ~) ~) (expect-eq !>([~ (from-list ~)]))
:: ::
++ test-from-list-real ++ test-from-list-real
(expect-eq (from-list [5 ~]) [~ 5]) (expect-eq !>([[~ 5] (from-list [5 ~])]))
:: ::
++ test-to-list-null ++ test-to-list-null
(expect-eq (to-list ~) ~) (expect-eq !>([~ (to-list ~)]))
:: ::
++ test-to-list-real ++ test-to-list-real
(expect-eq (to-list [~ 5]) [5 ~]) (expect-eq !>([[5 ~] (to-list [~ 5])]))
:: ::
++ test-concat-null ++ test-concat-null
(expect-eq (concat ~) ~) (expect-eq !>([~ (concat ~)]))
:: ::
++ test-concat-real ++ test-concat-real
:: wait, if i pull the cast out from below, the concat implementation :: wait, if i pull the cast out from below, the concat implementation
:: doesn't compile anymore? :: doesn't compile anymore?
(expect-eq (concat `(list (maybe @ud))`[~ [~ 1] ~ [~ 2] ~]) [1 2 ~]) (expect-eq !>([[1 2 ~] (concat `(list (maybe @ud))`[~ [~ 1] ~ [~ 2] ~])]))
:: ::
++ test-map ++ test-map
%+ expect-eq %- expect-eq !>
%+ map:myb :- [2 2 ~]
[1 2 3 2 ~] %+ map:myb
|=(a/@u ?:(=(2 a) [~ 2] ~)) [1 2 3 2 ~]
[2 2 ~] |=(a/@u ?:(=(2 a) [~ 2] ~))
-- --

View File

@ -4,24 +4,24 @@
=/ data/(list (either @u tape)) [[%& 1] [%| "one"] [%& 2] [%| "two"] ~] =/ data/(list (either @u tape)) [[%& 1] [%| "one"] [%& 2] [%| "two"] ~]
|_ _tester:tester |_ _tester:tester
++ test-apply ++ test-apply
%+ expect-eq %- expect-eq !>
%^ apply `(either @u tape)`[%| "one"] :- "right"
|=(a/@u "left") %^ apply `(either @u tape)`[%| "one"]
|=(b/tape "right") |=(a/@u "left")
"right" |=(b/tape "right")
:: ::
++ test-firsts ++ test-firsts
%+ expect-eq %- expect-eq !>
(firsts data) :- [1 2 ~]
[1 2 ~] (firsts data)
:: ::
++ test-seconds ++ test-seconds
%+ expect-eq %- expect-eq !>
(seconds data) :- ["one" "two" ~]
["one" "two" ~] (seconds data)
:: ::
++ test-partition ++ test-partition
%+ expect-eq %- expect-eq !>
(partition data) :- [[1 2 ~] ["one" "two" ~]]
[[1 2 ~] ["one" "two" ~]] (partition data)
-- --

View File

@ -87,9 +87,9 @@
%+ weld $(answers t.answers) %+ weld $(answers t.answers)
=+ `[bytes=@ud answer=@]`i.answers =+ `[bytes=@ud answer=@]`i.answers
%+ category.tst name %+ category.tst name
%+ expect-eq.tst %- expect-eq.tst !>
(hash bytes (~(got by keccak-inputs) bytes)) :- answer
answer (hash bytes (~(got by keccak-inputs) bytes))
:: ::
:: keccak :: keccak
:: ::
@ -241,63 +241,63 @@
:: sha3 :: sha3
:: ::
++ test-sha3-224 ++ test-sha3-224
%+ expect-eq.tst %- expect-eq.tst !>
(sha3-224 0 `@`0) :- 0x6b4e.0342.3667.dbb7.3b6e.1545.4f0e.b1ab.
0x6b4e.0342.3667.dbb7.3b6e.1545.4f0e.b1ab. d459.7f9a.1b07.8e3f.5b5a.6bc7
d459.7f9a.1b07.8e3f.5b5a.6bc7 (sha3-224 0 `@`0)
:: ::
++ test-sha3-256 ++ test-sha3-256
%+ expect-eq.tst %- expect-eq.tst !>
(sha3-256 0 `@`0) :- 0xa7ff.c6f8.bf1e.d766.51c1.4756.a061.d662.
0xa7ff.c6f8.bf1e.d766.51c1.4756.a061.d662. f580.ff4d.e43b.49fa.82d8.0a4b.80f8.434a
f580.ff4d.e43b.49fa.82d8.0a4b.80f8.434a (sha3-256 0 `@`0)
:: ::
++ test-sha3-384 ++ test-sha3-384
%+ expect-eq.tst %- expect-eq.tst !>
(sha3-384 0 `@`0) :- 0xc63.a75b.845e.4f7d.0110.7d85.2e4c.2485.
0xc63.a75b.845e.4f7d.0110.7d85.2e4c.2485. c51a.50aa.aa94.fc61.995e.71bb.ee98.3a2a.
c51a.50aa.aa94.fc61.995e.71bb.ee98.3a2a. c371.3831.264a.db47.fb6b.d1e0.58d5.f004
c371.3831.264a.db47.fb6b.d1e0.58d5.f004 (sha3-384 0 `@`0)
:: ::
++ test-sha3-512 ++ test-sha3-512
%+ expect-eq.tst %- expect-eq.tst !>
:- 0xa69f.73cc.a23a.9ac5.c8b5.67dc.185a.756e.
97c9.8216.4fe2.5859.e0d1.dcc1.475c.80a6.
15b2.123a.f1f5.f94c.11e3.e940.2c3a.c558.
f500.199d.95b6.d3e3.0175.8586.281d.cd26
(sha3-512 0 `@`0) (sha3-512 0 `@`0)
0xa69f.73cc.a23a.9ac5.c8b5.67dc.185a.756e. ::
97c9.8216.4fe2.5859.e0d1.dcc1.475c.80a6.
15b2.123a.f1f5.f94c.11e3.e940.2c3a.c558.
f500.199d.95b6.d3e3.0175.8586.281d.cd26
::
:: shake :: shake
:: ::
++ test-shake-128 ++ test-shake-128
%+ expect-eq.tst %- expect-eq.tst !>
(shake-128 512 0 `@`0) :- 0x7f9c.2ba4.e88f.827d.6160.4550.7605.853e.
0x7f9c.2ba4.e88f.827d.6160.4550.7605.853e. d73b.8093.f6ef.bc88.eb1a.6eac.fa66.ef26.
d73b.8093.f6ef.bc88.eb1a.6eac.fa66.ef26. 3cb1.eea9.8800.4b93.103c.fb0a.eefd.2a68.
3cb1.eea9.8800.4b93.103c.fb0a.eefd.2a68. 6e01.fa4a.58e8.a363.9ca8.a1e3.f9ae.57e2
6e01.fa4a.58e8.a363.9ca8.a1e3.f9ae.57e2 (shake-128 512 0 `@`0)
:: ::
++ test-shake-256 ++ test-shake-256
%+ expect-eq.tst %- expect-eq.tst !>
(shake-256 512 0 `@`0) :- 0x46b9.dd2b.0ba8.8d13.233b.3feb.743e.eb24.
0x46b9.dd2b.0ba8.8d13.233b.3feb.743e.eb24. 3fcd.52ea.62b8.1b82.b50c.2764.6ed5.762f.
3fcd.52ea.62b8.1b82.b50c.2764.6ed5.762f. d75d.c4dd.d8c0.f200.cb05.019d.67b5.92f6.
d75d.c4dd.d8c0.f200.cb05.019d.67b5.92f6. fc82.1c49.479a.b486.4029.2eac.b3b7.c4be
fc82.1c49.479a.b486.4029.2eac.b3b7.c4be (shake-256 512 0 `@`0)
:: ::
++ test-rawshake-128 ++ test-rawshake-128
%+ expect-eq.tst %- expect-eq.tst !>
(rawshake-128 512 0 `@`0) :- 0xfa01.9a3b.1763.0df6.0148.53b5.4707.73f1.
0xfa01.9a3b.1763.0df6.0148.53b5.4707.73f1. 3c3a.b704.4782.11d7.a658.6751.5dea.1cc7.
3c3a.b704.4782.11d7.a658.6751.5dea.1cc7. 926b.2147.e396.076b.22cb.7263.3af5.0647.
926b.2147.e396.076b.22cb.7263.3af5.0647. c7f2.3d0d.8f00.1d6d.8daf.0f6f.2e92.fc0e
c7f2.3d0d.8f00.1d6d.8daf.0f6f.2e92.fc0e (rawshake-128 512 0 `@`0)
:: ::
++ test-rawshake-256 ++ test-rawshake-256
%+ expect-eq.tst %- expect-eq.tst !>
(rawshake-256 512 0 `@`0) :- 0x3a11.08d4.a90a.31b8.5a10.bdce.77f4.bfbd.
0x3a11.08d4.a90a.31b8.5a10.bdce.77f4.bfbd. cc5b.1d70.dd40.5686.f8bb.de83.4aa1.a410.
cc5b.1d70.dd40.5686.f8bb.de83.4aa1.a410. db8c.9e1c.166c.3e23.9cd7.6a55.f6a6.92aa.
db8c.9e1c.166c.3e23.9cd7.6a55.f6a6.92aa. 2d17.49f2.ec79.cd0b.a3b1.7bb6.5995.9b6e
2d17.49f2.ec79.cd0b.a3b1.7bb6.5995.9b6e (rawshake-256 512 0 `@`0)
-- --