summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'data/unit-testing/cast.fate')
-rw-r--r--data/unit-testing/cast.fate103
1 files changed, 103 insertions, 0 deletions
diff --git a/data/unit-testing/cast.fate b/data/unit-testing/cast.fate
new file mode 100644
index 0000000..94b8beb
--- /dev/null
+++ b/data/unit-testing/cast.fate
@@ -0,0 +1,103 @@
+(fate_version 1)
+
+(global string test_name)
+
+(set test_name ( CAST ))
+
+(global int i)
+(global float f)
+(global string s)
+
+(set i (cast int ( 42 )))
+
+(assert (= (var i) 42) [FAILED] (var test_name) equality 1: (var i).)
+
+(set f (cast float ( 42.57 )))
+
+(assert (= (var f) 42.57) [FAILED] (var test_name) equality 2: (var f).)
+
+(assert (= (var i) 42 (cast int (var f))) [FAILED] (var test_name) equality 3: (cast int (var f)).)
+
+
+;; TO INT
+(assert (= 42 (cast int 42.72)) [FAILED] (var test_name) float->int: (cast int 42.72).)
+(assert (= 42 (cast int (+ 40.70 2.02))) [FAILED] (var test_name) extra float->int: (cast int (+ 40.70 2.02)).)
+(assert (= 42 (cast int 42)) [FAILED] (var test_name) int->int: (cast int 42).)
+(assert (= 42 (cast int (+ 40 2))) [FAILED] (var test_name) extra int->int: (cast int (+ 40 2)).)
+(assert (= 42 (cast int ( 42 ))) [FAILED] (var test_name) string->int: (cast int ( 42 )).)
+
+;; TO FLOAT
+(assert
+ (>
+ 0.05
+ (abs
+ (-
+ (cast float 42.72)
+ 42.72
+ )
+ )
+ )
+ [FAILED] (var test_name) float->float: (cast float 42.72).
+)
+(assert
+ (> 0.05
+ (abs
+ (-
+ (cast float (+ 40.70 2.02))
+ 42.72
+ )
+ )
+ )
+ [FAILED] (var test_name) extra float->float: (cast float (+ 40.70 2.02)).
+)
+(assert (= 42.0 (cast float 42)) [FAILED] (var test_name) int->float: (cast float 42).)
+(assert (= 42.0 (cast float (+ 40 2))) [FAILED] (var test_name) extra float->float: (cast float (+ 40 2)).)
+(assert
+ (> 0.05
+ (abs
+ (-
+ (cast float ( 42.72 ))
+ 42.72
+ )
+ )
+ )
+ [FAILED] (var test_name) string->float: (cast float ( 42.72 )).
+)
+
+;; TO BOOL
+(assert (= (true) (cast bool (true))) [FAILED] (var test_name) bool->bool: (cast bool (true)).)
+(assert (= (true) (cast bool (or (true) (false)))) [FAILED] (var test_name) extra bool->bool: (cast bool (or (true) (false))).)
+(assert (= (true) (cast bool ( true ))) [FAILED] (var test_name) string->bool: (cast bool ( true )).)
+
+;; TO STRING
+(assert (= ( 42 ) (cast string 42)) [FAILED] (var test_name) int->string: (cast string 42).)
+(assert (= ( 42 ) (cast string (+ 40 2))) [FAILED] (var test_name) extra int->string: (cast string (+ 40 2)).)
+(assert
+ (> 0.05
+ (abs
+ (-
+ (cast float (cast string 42.72))
+ 42.72
+ )
+ )
+ )
+ [FAILED] (var test_name) float->string: (cast string 42.72).
+)
+(assert
+ (> 0.05
+ (abs
+ (-
+ (cast float (cast string (+ 40.7 2.02)))
+ 42.72
+ )
+ )
+ )
+ [FAILED] (var test_name) extra float->string: (cast string (+ 40.7 2.02)).
+)
+(assert (= ( true ) (cast string (true))) [FAILED] (var test_name) bool->string: (cast string (true)).)
+(assert (= ( true ) (cast string (or (true) (false)))) [FAILED] (var test_name) extra bool->string: (cast string (true)).)
+(assert (= ( something ) (cast string ( something ))) [FAILED] (var test_name) string->string: (cast string ( something )).)
+
+[COMPLETED] (var test_name)
+
+(end)