nim-stint/tests/test_int_initialization.nim

58 lines
1.2 KiB
Nim
Raw Permalink Normal View History

2023-06-13 12:51:49 +00:00
# Stint
# Copyright 2018-2023 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.
import ../stint, unittest, test_helpers
template testInitialization(chk, tst: untyped) =
tst "zero one":
var a: StInt[128]
a.setZero
chk a == 0.i128
var b: StInt[256]
b.setZero
chk b == 0.i256
var aa: StInt[128]
aa.setOne
chk aa == 1.i128
var bb: StInt[256]
bb.setOne
chk bb == 1.i256
var xx = StInt[128].zero
chk xx == 0.i128
var yy = StInt[256].zero
chk yy == 0.i256
var uu = StInt[128].one
chk uu == 1.i128
var vv = StInt[256].one
chk vv == 1.i256
tst "hi lo":
let x = Int128.high
var z = UInt128.high
2023-06-13 14:53:19 +00:00
z.clearBit(z.bits - 1)
2023-06-15 07:31:59 +00:00
chk x.impl == z
2023-06-13 12:51:49 +00:00
let xx = Int128.low
var zz = UInt128.low
2023-06-13 13:39:22 +00:00
zz.setBit(z.bits - 1)
2023-06-15 07:31:59 +00:00
chk xx.impl == zz
2023-06-13 12:51:49 +00:00
2023-06-14 02:41:01 +00:00
static:
testInitialization(ctCheck, ctTest)
2023-06-13 12:51:49 +00:00
suite "Signed integer initialization":
testInitialization(check, test)