]> ocean-lang.org Git - ocean/blobdiff - csrc/oceani-tests.mdc
oceani: introduce 'test' and 'choose' operators
[ocean] / csrc / oceani-tests.mdc
index 7a408179378b67a59b15062e2ed0946eb417575f..f9dce403d3e83f9920736e06853676778bfd7198 100644 (file)
@@ -97,7 +97,7 @@ arguments separated from the name by commas.  For each test, there is a section
                ## valgrind test code
                @[ -n "$$SKIP_COVERAGE_CHECK" ] || awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \
                    END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \
-                        if (ran < (ran + skip) *0.968) exit(1) }' \
+                        if (ran < (ran + skip) *0.972) exit(1) }' \
                        coverage/oceani.mdc.gcov
 
        coverage_oceani: oceani.c
@@ -134,14 +134,26 @@ calculations on them.
                  + b1
                  + b
 
+               z:Boolean= True
+               w:Boolean = False
+               if ?z:
+                       print "w??z", w??z
+                       print "z??w", z??w
+                       print "z??False", z??False, "w??False", w??False
+               if ?w:
+                       print "Weird?"
+
 ###### output: valvar
 
-       23 12 35 11 276 1.91667 11
+       23 12 35 11 276 1.916666667 11
        False False True True False False True
        23 12 12 -23 -12 12
        False True True False False False
        This is a string  field theory This is a string field theory
        81
+       w??z True
+       z??w True
+       z??False True w??False False
 
 Next we change the value of variables
 
@@ -158,7 +170,7 @@ Next we change the value of variables
                print a, a/a
 
 ###### output: setvar
-       1.07374e+09 1
+       1073741824 1
 
 Now some contants
 
@@ -167,6 +179,7 @@ Now some contants
 
 ###### test: consts
        const
+               tau ::= pi * 2
                pi ::= 3.141 592 653
                four ::= 2 + 2 ; five ::= 10/2
        const pie ::= "I like Pie";
@@ -176,12 +189,12 @@ Now some contants
        func main()
                print "Hello World, what lovely oceans you have!"
                print "are there", five, "?"
-               print pi, pie, "but", cake
+               print pi, pie, "but", cake, "Tau is", tau
 
 ###### output: consts
        Hello World, what lovely oceans you have!
        are there 5 ?
-       3.14159 I like Pie but The cake is a lie
+       3.141592653 I like Pie but The cake is a lie Tau is 6.283185306
 
 Test merging of variables from multiple cases
 
@@ -280,13 +293,13 @@ Now we need to test if/else and some different loops
        Success
         1 2 4 8 16 32 64
        0 1.5
-       1 1.41667
-       2 1.41422
-       3 1.41421
-       error is  -4.51095e-12
+       1 1.416666667
+       2 1.414215686
+       3 1.414213562
+       error is  -4.510950445e-12
        I won't calculate 20 / 0
-       20 / 3  = 6.66667
-       20 / 6  = 3.33333
+       20 / 3  = 6.666666667
+       20 / 6  = 3.333333333
        I won't calculate 20 / 9
        Close enough
        higher
@@ -392,7 +405,7 @@ Here I break it into two parts, keeping the array code separate.
        GCD of 55 and 33 is 11
        Fibonacci: 1 1 2 3 5 8 13 21 34 55 89 144
        hello was the str
-       Closest I found was 77.3438
+       Closest I found was 77.34375
 
 ###### output: sayhello,12,60,there,False
        Hello World, what lovely oceans you have!
@@ -402,7 +415,7 @@ Here I break it into two parts, keeping the array code separate.
        GCD of 12 and 60 is 12
        Fibonacci: 1 1 2 3 5 8 13 21 34 55 89 144
        I found the str over there
-       Closest I found was 77.3438
+       Closest I found was 77.34375
 
 ###### test list
        oceani_tests += "insert_sort"
@@ -584,6 +597,7 @@ Time to test if structure declarations and accesses work correctly.
        struct foo
                size:[three]number
                name:string
+               thing:baz
                active:Boolean = True
 
        struct baz { a:number; b:Boolean; }
@@ -606,6 +620,7 @@ Time to test if structure declarations and accesses work correctly.
 
                for i:=0; then i=i+1; while i < 4:
                        print info[i].name, info[i].active, info[i].size[0]
+               info[0].thing.b = True
 
 ###### output: structs
 
@@ -647,9 +662,21 @@ Test functions.  They don't return anything, so we need to get them to print
                        test(n-1, "."++s)
                else
                        print "done"
+
+       func to_polar
+               x:number; y:number
+       return
+               rho:number
+               theta:number
+       do
+               rho = x + y
+               theta = x - y
+
        func main()
                for i:=0; then i = i + 1; while i < 5:
                        test(i, " ")
+               angular := to_polar(32, 23)
+               print angular.rho, angular.theta
 
 ###### output: functions
        done
@@ -657,6 +684,7 @@ Test functions.  They don't return anything, so we need to get them to print
        2  1 . done
        3  2 . 1 .. done
        4  3 . 2 .. 1 ... done
+       55 9
 
 ###### test: func_ret_type
 
@@ -762,10 +790,10 @@ separate file first, then run from there.
                This is a multiline string
                With an unsupportable suffix
                """Aa
-       .tmp.code:14:11: error: undefined type: unknown
        .tmp.code:15:12: error: name undeclared: unknowable
        .tmp.code:17:12: error: array size must be a constant: zzsize
        .tmp.code:20:12: error: unrecognised number: 00123
+       .tmp.code:14:11: error: type used but not declared: unknown
 
 ## Tests for type errors
 
@@ -778,7 +806,7 @@ These programs were generated by looking for the
 various places that `type_err()` are called.
 
 ###### test list
-       oceani_failing_tests += type_err1 type_err2 type_err3 type_err4
+       oceani_failing_tests += type_err1 type_err2 type_err3 type_err4 type_err5 type_err6
 
 ###### test: type_err1
 
@@ -907,8 +935,38 @@ various places that `type_err()` are called.
        .tmp.code:3:14: info: variable 'b' was set as none here.
        oceani: type error in program - not running.
 
+###### test: type_err5
+       struct foo
+               bar:baz
+               a:number
+       struct baz
+               bat:foo
+               b:string
+       struct foo
+               c:number
+
+###### output: type_err5
+       .tmp.code:8:7: error: type already declared: foo
+       .tmp.code:2:7: info: this is location of declartion: foo
+       .tmp.code:2:7: error: type has recursive definition: foo
+       .tmp.code:5:7: error: type has recursive definition: baz
+
+###### test: type_err6
+
+       func main()
+               a:= "hello"
+               if ?a:
+                       print "no"
+               print a ?? "there"
+
+###### output: type_err6
+       .tmp.code:4:12: error: '?' requires a testable value, not string
+       .tmp.code:6:14: error: "??" requires a testable value, not string
+       oceani: type error in program - not running.
+
+
 ###### test list
-       oceani_failing_tests += type_err_const type_err_const1 missing_program bad_main
+       oceani_failing_tests += type_err_const type_err_const1 type_err_const2 missing_program bad_main
 
 ###### test: type_err_const
        const
@@ -926,7 +984,6 @@ various places that `type_err()` are called.
                print bar, foo
 
 ###### output: type_err_const
-       .tmp.code:4:16: error: expected number found string
        .tmp.code:6:8: error: name already declared: bar
        .tmp.code:4:8: info: this is where 'bar' was first declared
        .tmp.code:8:8: error: variable 'foo' redeclared
@@ -935,6 +992,7 @@ various places that `type_err()` are called.
        .tmp.code:7:5: info: this is where 'main' was first declared
        .tmp.code:13:8: error: variable 'foo' redeclared
        .tmp.code:3:8: info: this is where 'foo' was first declared
+       .tmp.code:4:16: error: expected number found string
 
 ###### test: type_err_const1
        const
@@ -948,6 +1006,15 @@ various places that `type_err()` are called.
        .tmp.code:3:12: Syntax error in constant: :
        .tmp.code:4:12: Syntax error in constant: :
 
+###### test: type_err_const2
+       const
+               four ::= two + two
+               two ::= four / 2
+       
+###### output: type_err_const2
+       .tmp.code:3:8: error: const four cannot be resolved.
+       .tmp.code:4:8: error: const two cannot be resolved.
+
 ###### test: missing_program
        const
                foo::="bar"
@@ -960,7 +1027,7 @@ various places that `type_err()` are called.
                print foo
 
 ###### output: bad_main
-       .tmp.code:??:??: error: expected  argv but variable 'foo' is string
+       .tmp.code:??:??: error: expected []string but variable 'foo' is string
        .tmp.code:??:??: info: this is where 'NOTVAR' was set to string
        oceani: main has wrong type.
 
@@ -1021,8 +1088,8 @@ Test for type errors with functions
        .tmp.code:20:14: error: attempt to call a non-function.
        .tmp.code:20:32: error: expected string found number
        .tmp.code:20:28: error: insufficient arguments to function.
-       .tmp.code:21:20: error: expected  func but variable 'test2' is  func
-       .tmp.code:??:??: info: this is where 'NOTVAR' was set to  func
+       .tmp.code:21:20: error: expected *invalid*type* but variable 'test2' is *invalid*type*
+       .tmp.code:??:??: info: this is where 'NOTVAR' was set to *invalid*type*
        .tmp.code:10:14: error: variable used but not declared: a
        .tmp.code:10:17: error: variable used but not declared: z
        oceani: type error in program - not running.