Sfoglia il codice sorgente

Added more comprehensive unit tests for list map, filter, and reduce

MatanSilver 8 anni fa
parent
commit
bd198f8b5f

+ 15 - 2
test/unittest/list_filter.gravity

@@ -1,6 +1,6 @@
 #unittest {
     name: "List filter.";
-    result: "[3,12,6,24]";
+    result: true;
 };
 
 func main() {
@@ -8,5 +8,18 @@ func main() {
   func x(a) {
     return !(a % 3) //! needed because modulo returns 0 if divisible
   }
-  return list.filter(x).String()
+  if (list.filter(x).String() != "[3,12,6,24]") {
+    return false
+  }
+  var list2 = ["this", "is", "a", "test"]
+  func y(a) {
+    if (a.length > 3) {
+      return true
+    }
+    return false
+  }
+  if (list2.filter(y).String() != ["this","test"].String()) {
+    return false
+  }
+  return true
 }

+ 12 - 2
test/unittest/list_map.gravity

@@ -1,6 +1,6 @@
 #unittest {
     name: "List map.";
-    result: "[0,1,0,1,0,1]";
+    result: true;
 };
 
 func main() {
@@ -8,5 +8,15 @@ func main() {
   func x(a) {
     return a % 2
   }
-  return list.map(x).String()
+  if (list.map(x).String() != "[0,1,0,1,0,1]") {
+    return false
+  }
+  var list2 = ["this", "is", "a", "test"]
+  func y(a) {
+    return a.length
+  }
+  if (list2.map(y).String() != "[4,2,1,4]") {
+    return false
+  }
+  return true
 }

+ 9 - 2
test/unittest/list_reduce.gravity

@@ -1,6 +1,6 @@
 #unittest {
     name: "List reduce.";
-    result: "thisisatest";
+    result: true;
 };
 
 func main() {
@@ -9,9 +9,16 @@ func main() {
     return a - b
   }
   var reduced = list.reduce(-1, x) //-22
+  if (reduced != -22) {
+    return false
+  }
   var list2 = ["this","is","a","test"]
   func y(a, b) {
     return a + b
   }
-  return list2.reduce("", y)
+  reduced = list2.reduce("", y)
+  if (reduced != "thisisatest") {
+    return false
+  }
+  return true
 }