← nimrepo

unittests

6ca31ccfdb619ad058b940018a0deadef15b56bd · ovidiucs · Feb 10, 2019 17:09

+39 −6 · 2 files changed

  • stuff.nim +0 −6
  • unittesting.nim +39 −0
diff --git a/stuff.nim b/stuff.nim
index 362272c..1f28524 100644
--- a/stuff.nim
+++ b/stuff.nim
@@ -118,9 +118,3 @@ template foo3(): untyped =
   [1, 2]
 echo foo3
 
-
-proc abc(str:string) =
-  echo str 
-
-
-echo abc("test")
diff --git a/unittesting.nim b/unittesting.nim
new file mode 100644
index 0000000..9857810
--- /dev/null
+++ b/unittesting.nim
@@ -0,0 +1,39 @@
+# Copyright 2019.
+import unittest
+type
+  Card = object
+    rank: Rank
+    suit: Suit
+  Rank = enum
+    crSeven
+    crEight
+    crNine
+    crTen
+    crJack
+    crQueen
+    crKing
+    crAce
+  Suit = enum
+    csClubs = "♧"
+    csDiamonds = "♢"
+    csHearts = "♡"
+    csSpades = "♤"
+
+proc `<`(a,b: Card): bool = a.rank  < b.rank
+proc `==`(a,b: Card): bool = a.rank == b.rank
+when isMainModule:
+  let
+    aceDiamonds = Card(rank: crAce, suit: csDiamonds)
+    kingClubs = Card(rank: crKing, suit: csClubs)
+    aceClubs = Card(rank: crAce, suit: csClubs)
+
+echo "Begin tests"
+#test1
+test "greater than":
+  check:
+    aceDiamonds > kingClubs
+    aceClubs > kingClubs
+#test2
+test "equal to":
+  check:
+    aceDiamonds == aceClubs