No description
Find a file
2023-02-23 23:41:15 +01:00
src remove debug output 2023-02-23 23:41:15 +01:00
tests simplified tree example 2022-06-23 00:26:55 +02:00
.gitignore init 2022-06-03 16:49:50 +02:00
LICENSE.md add license 2022-06-03 21:08:24 +02:00
README.md simplified tree example 2022-06-23 00:26:55 +02:00
receq.nimble tick version 2023-02-23 23:38:24 +01:00

RecEq

receq defines the ==* and !=* operator to recursively compare 2 ref objects.
It also works for not recursive and mutual recursive types.
ref types that are no objects just get derefferenced and compared with ==

Litle Example

more can be found in the tests

type Tree = ref object
  val: int
  case isLeaf: bool
    of false: left, right: Tree
    else: discard

func val(x: int ): Tree = Tree(isLeaf: true, val: x)
func val(x: Tree): Tree = x

func tree(l: int|Tree, x: int, r: int|Tree): Tree =
  Tree(isLeaf: false, left: val l, val: x, right: val r)

assert: val(1) ==* val(1)
assert: val(1) !=* val(2)
assert: val(1) !=* tree(1, 2, 3)
assert: tree(tree(1, 2, 3), 4, tree(tree(5, 6, 7), 8, 9)) ==* tree(tree(1, 2, 3), 4, tree(tree(5, 6, 7), 8, 9))
assert: tree(tree(1, 2, 3), 4, tree(tree(5, 6, 7), 8, 9)) !=* tree(tree(1, 2, 3), 4, tree(tree(6, 6, 7), 8, 9))
assert: tree(tree(1, 2, 3), 4, tree(tree(5, 6, 7), 8, 9)) !=* tree(tree(1, 2, 3), 4, tree(5, 8, 9))