File: uint_spec.cr

package info (click to toggle)
crystal 1.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 24,384 kB
  • sloc: javascript: 6,400; sh: 695; makefile: 269; ansic: 121; python: 105; cpp: 77; xml: 32
file content (61 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require "spec"

describe "UInt" do
  it "compares with <=>" do
    (1_u32 <=> 0_u32).should eq(1)
    (0_u32 <=> 0_u32).should eq(0)
    (0_u32 <=> 1_u32).should eq(-1)
  end

  describe "&-" do
    it "returns the wrapped negation" do
      x = &-0_u32
      x.should eq(0_u32)
      x.should be_a(UInt32)

      x = &-100_u8
      x.should eq(156_u8)
      x.should be_a(UInt8)

      x = &-1_u8
      x.should eq(255_u8)
      x.should be_a(UInt8)

      x = &-255_u8
      x.should eq(1_u8)
      x.should be_a(UInt8)

      x = &-1_u16
      x.should eq(65535_u16)
      x.should be_a(UInt16)

      x = &-65535_u16
      x.should eq(1_u16)
      x.should be_a(UInt16)

      x = &-1_u32
      x.should eq(4294967295_u32)
      x.should be_a(UInt32)

      x = &-4294967295_u32
      x.should eq(1_u32)
      x.should be_a(UInt32)

      x = &-1_u64
      x.should eq(18446744073709551615_u64)
      x.should be_a(UInt64)

      x = &-18446744073709551615_u64
      x.should eq(1_u64)
      x.should be_a(UInt64)

      x = &-1_u128
      x.should eq(UInt128::MAX) # TODO: Change to literal once supported
      x.should be_a(UInt128)

      x = &-(UInt128::MAX) # TODO: Change to literal once supported
      x.should eq(1_u128)
      x.should be_a(UInt128)
    end
  end
end