aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux.lux22
-rw-r--r--stdlib/source/test/lux/data/collection/dictionary.lux55
-rw-r--r--stdlib/source/test/lux/ffi.jvm.lux130
3 files changed, 168 insertions, 39 deletions
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index e7ad9d03c..cbc63d90d 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -711,6 +711,27 @@
(n.= expected/s)))))
)))
+(def: for_associative
+ Test
+ (do random.monad
+ [left (random.ascii/lower 1)
+ mid (random.ascii/lower 1)
+ right (random.ascii/lower 1)
+ #let [expected (text.join_with "" (list left mid right))]]
+ (_.cover [/.$_ /._$]
+ (with_expansions [<left_association> (/._$ format
+ left
+ mid
+ right)
+ <right_association> (/.$_ format
+ left
+ mid
+ right)]
+ (and (text\= <left_association>
+ <right_association>)
+ (not (code\= (' <left_association>)
+ (' <right_association>))))))))
+
(def: test
Test
(<| (_.covering /._)
@@ -738,6 +759,7 @@
..for_template
..for_static
..for_slot
+ ..for_associative
..sub_tests
)))
diff --git a/stdlib/source/test/lux/data/collection/dictionary.lux b/stdlib/source/test/lux/data/collection/dictionary.lux
index c38df7030..541092b4e 100644
--- a/stdlib/source/test/lux/data/collection/dictionary.lux
+++ b/stdlib/source/test/lux/data/collection/dictionary.lux
@@ -13,9 +13,10 @@
["." exception]]
[data
["." product]
- ["." maybe]
+ ["." maybe ("#\." functor)]
[collection
- ["." list ("#\." functor)]]]
+ ["." list ("#\." functor)]
+ ["." set]]]
[math
["." random]
[number
@@ -61,11 +62,51 @@
(_.cover [/.key_hash]
(is? hash (/.key_hash (/.new hash)))))
- (_.cover [/.entries /.keys /.values]
- (\ (list.equivalence (product.equivalence n.equivalence n.equivalence)) =
- (/.entries dict)
- (list.zip/2 (/.keys dict)
- (/.values dict))))
+ (_.cover [/.entries]
+ (let [entries (/.entries dict)
+
+ correct_size!
+ (n.= (/.size dict)
+ (list.size entries))
+
+ unique_keys!
+ (|> entries
+ (list\map product.left)
+ (set.from_list n.hash)
+ set.size
+ (n.= (/.size dict)))
+
+ correct_pairing!
+ (list.every? (function (_ [key value])
+ (|> dict
+ (/.get key)
+ (maybe\map (n.= value))
+ (maybe.default false)))
+ entries)]
+ (and correct_size!
+ unique_keys!
+ correct_pairing!)))
+ (_.cover [/.keys]
+ (let [keys (/.keys dict)
+
+ correct_size!
+ (n.= (/.size dict)
+ (list.size keys))
+
+ unique_keys!
+ (|> keys
+ (set.from_list n.hash)
+ set.size
+ (n.= (/.size dict)))
+
+ recognized!
+ (list.every? (/.key? dict) keys)]
+ (and correct_size!
+ unique_keys!
+ recognized!)))
+ (_.cover [/.values]
+ (n.= (/.size dict)
+ (list.size (/.values dict))))
(_.cover [/.merge]
(let [merging_with_oneself (let [(^open ".") (/.equivalence n.equivalence)]
diff --git a/stdlib/source/test/lux/ffi.jvm.lux b/stdlib/source/test/lux/ffi.jvm.lux
index ba02b1fc9..e8e07e7e1 100644
--- a/stdlib/source/test/lux/ffi.jvm.lux
+++ b/stdlib/source/test/lux/ffi.jvm.lux
@@ -27,30 +27,17 @@
[\\library
["." /]])
-(/.import: (java/util/concurrent/Callable a))
-
+(/.import: java/lang/Boolean)
(/.import: java/lang/Long)
(/.import: java/lang/String)
-(/.import: java/lang/Exception
- ["#::."
- (new [java/lang/String])])
-
(/.import: java/lang/Object)
(/.import: (java/lang/Class a)
["#::."
(getName [] java/lang/String)])
-(/.import: java/lang/Runnable)
-
-(/.import: java/lang/System
- ["#::."
- (#static out java/io/PrintStream)
- (#static currentTimeMillis [] #io long)
- (#static getenv [java/lang/String] #io #? java/lang/String)])
-
## TODO: Handle "/.class:" ASAP.
## (/.class: #final (TestClass A) [java/lang/Runnable]
## ## Fields
@@ -70,23 +57,6 @@
## (java/lang/Runnable [] (run self) void
## []))
-(def: test_runnable
- (/.object [] [java/lang/Runnable]
- []
- (java/lang/Runnable
- [] (run self) void
- [])))
-
-(def: test_callable
- (/.object [a] [(java/util/concurrent/Callable a)]
- []
- ((java/util/concurrent/Callable a)
- [] (call self) a #throws [java/lang/Exception]
- (undefined))))
-
-## (/.interface: TestInterface
-## ([] foo [boolean java/lang/String] void #throws [java/lang/Exception]))
-
(template [<name> <type> <conversion> <lux> <=>]
[(def: (<name> left right)
(-> <type> <type> Bit)
@@ -262,9 +232,105 @@
(type\= /.Character (/.type char)))))
))))
+(/.interface: test/TestInterface0
+ ([] actual0 [] java/lang/Long))
+
+(/.import: test/TestInterface0
+ ["#::."
+ (actual0 [] java/lang/Long)])
+
+(/.interface: test/TestInterface1
+ ([] actual1 [java/lang/Boolean] java/lang/Long #throws [java/lang/Throwable]))
+
+(/.import: test/TestInterface1
+ ["#::."
+ (actual1 [java/lang/Boolean] #try java/lang/Long)])
+
+(/.interface: test/TestInterface2
+ ([a] actual2 [a] a))
+
+(/.import: test/TestInterface2
+ ["#::."
+ ([a] actual2 [a] a)])
+
+(/.interface: (test/TestInterface3 a)
+ ([] actual3 [] a))
+
+(/.import: (test/TestInterface3 a)
+ ["#::."
+ (actual3 [] a)])
+
+(def: interface
+ (do random.monad
+ [expected random.nat
+ #let [object/0 (/.object [] [test/TestInterface0]
+ []
+ (test/TestInterface0
+ [] (actual0 self)
+ java/lang/Long
+ (:as java/lang/Long
+ expected)))
+ object/1 (/.object [] [test/TestInterface1]
+ []
+ (test/TestInterface1
+ [] (actual1 self {throw? java/lang/Boolean})
+ java/lang/Long
+ #throws [java/lang/Throwable]
+ (if (:as Bit throw?)
+ (error! "YOLO")
+ (:as java/lang/Long
+ expected))))
+ object/2 (/.object [] [test/TestInterface2]
+ []
+ (test/TestInterface2
+ [a] (actual2 self {input a})
+ a
+ input))
+ object/3 (/.object [] [(test/TestInterface3 java/lang/Long)]
+ []
+ ((test/TestInterface3 a)
+ [] (actual3 self)
+ a
+ (:as java/lang/Long
+ expected)))
+
+ example/0!
+ (is? (: Any expected)
+ (: Any (test/TestInterface0::actual0 object/0)))
+
+ example/1!
+ (and (case (test/TestInterface1::actual1 false object/1)
+ (#try.Success actual)
+ (is? (: Any expected)
+ (: Any actual))
+
+ (#try.Failure error)
+ false)
+ (case (test/TestInterface1::actual1 true object/1)
+ (#try.Success actual)
+ false
+
+ (#try.Failure error)
+ true))
+
+ example/2!
+ (is? (: Any expected)
+ (: Any (test/TestInterface2::actual2 (:as /.Long expected) object/2)))
+
+ example/3!
+ (is? (: Any expected)
+ (: Any (test/TestInterface3::actual3 object/3)))]]
+ (_.cover [/.interface:]
+ (and example/0!
+ example/1!
+ example/2!
+ example/3!))))
+
(def: #export test
(<| (_.covering /._)
($_ _.and
..conversions
..arrays
- ..miscellaneous)))
+ ..miscellaneous
+ ..interface
+ )))