nim-stint/tests/test_uint_comparison.nim

65 lines
1.4 KiB
Nim
Raw Normal View History

# Stint
2018-03-02 10:48:08 +00:00
# Copyright 2018 Status Research & Development GmbH
# Licensed under either of
#
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
#
# at your option. This file may not be copied, modified, or distributed except according to those terms.
2018-05-08 13:51:55 +00:00
import ../stint, unittest
suite "Testing unsigned int comparison operators":
let
a = 10'i16.stuint(16)
b = 15'i16.stuint(16)
c = 150'u16
d = 4.stuint(128) shl 64
e = 4.stuint(128)
f = 4.stuint(128) shl 65
test "< operator":
check:
a < b
not (a + b < b)
not (a + a + a < b + b)
2018-04-25 10:52:00 +00:00
not (a * b < cast[StUint[16]](c))
e < d
d < f
test "<= operator":
check:
a <= b
not (a + b <= b)
a + a + a <= b + b
2018-04-25 10:52:00 +00:00
a * b <= cast[StUint[16]](c)
e <= d
d <= f
test "> operator":
check:
b > a
not (b > a + b)
not (b + b > a + a + a)
2018-04-25 10:52:00 +00:00
not (cast[StUint[16]](c) > a * b)
d > e
f > d
test ">= operator":
check:
b >= a
not (b >= a + b)
b + b >= a + a + a
2018-04-25 10:52:00 +00:00
cast[StUint[16]](c) >= a * b
d >= e
f >= d
test "isOdd/isEven":
check:
a.isEven
not a.isOdd
b.isOdd
not b.isEven
c.isEven
not c.isOdd