PageRenderTime 52ms CodeModel.GetById 45ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/test/lib/numeric/natural/test_natural4.e

http://github.com/tybor/Liberty
Specman e | 103 lines | 80 code | 21 blank | 2 comment | 0 complexity | 573c9c5a2c55f6785d995b1401eea364 MD5 | raw file
  1class TEST_NATURAL4
  2   
  3inherit
  4   EIFFELTEST_TOOLS
  5
  6create {}
  7   main
  8
  9feature {}
 10   main
 11      local
 12         n64: NATURAL_64; debug_view: STRING
 13      do
 14         -- Testing {NUMBER}.is_natural_64:
 15         assert(("0").to_number.is_natural_64)
 16         assert(("255").to_number.is_natural_64)
 17         assert(("256").to_number.is_natural_64)
 18         assert(("65535").to_number.is_natural_64)
 19         assert(("65536").to_number.is_natural_64)
 20         assert(("4294967295").to_number.is_natural_64)
 21         assert(("4294967296").to_number.is_natural_64)
 22         assert(("18446744073709551615").to_number.is_natural_64)
 23
 24         assert(not ("-1").to_number.is_natural_64)
 25         assert(not ("18446744073709551616").to_number.is_natural_64)
 26
 27         -- Testing {NUMBER}.to_natural_64:
 28         n64 := ("0").to_number.to_natural_64
 29         assert(n64 = 0.to_natural_64)
 30         debug_view := n64.to_string
 31         assert(n64.to_string.is_equal("0"))
 32
 33         n64 := ("255").to_number.to_natural_64
 34         assert(n64 = 255.to_natural_64)
 35         debug_view := n64.to_string
 36         assert(n64.to_string.is_equal("255"))
 37         
 38         n64 := ("256").to_number.to_natural_64
 39         assert(n64 = 256.to_natural_64)
 40         debug_view := n64.to_string
 41         assert(n64.to_string.is_equal("256"))
 42
 43         n64 := ("65535").to_number.to_natural_64
 44         assert(n64 = 65535.to_natural_64)
 45         debug_view := n64.to_string
 46         assert(n64.to_string.is_equal("65535"))
 47
 48         n64 := ("65536").to_number.to_natural_64
 49         assert(n64 = 65536.to_natural_64)
 50         debug_view := n64.to_string
 51         assert(n64.to_string.is_equal("65536"))
 52
 53         n64 := ("4294967295").to_number.to_natural_64
 54         assert(n64 = 4294967295.to_natural_64)
 55         debug_view := n64.to_string
 56         assert(n64.to_string.is_equal("4294967295"))
 57
 58         n64 := ("4294967296").to_number.to_natural_64
 59         assert(n64 = 4294967296.to_natural_64)
 60         debug_view := n64.to_string
 61         assert(n64.to_string.is_equal("4294967296"))
 62         
 63         n64 := ("18446744073709551614").to_number.to_natural_64
 64         debug_view := n64.to_string
 65         assert(n64.to_string.is_equal("18446744073709551614"))
 66
 67         n64 := ("18446744073709551615").to_number.to_natural_64
 68         debug_view := n64.to_string
 69         assert(n64.to_string.is_equal("18446744073709551615"))
 70
 71         debug_view := 0.to_natural_8.bit_not.to_string
 72         assert(debug_view.is_equal("255"))
 73         
 74         debug_view := 0.to_natural_16.bit_not.to_string
 75         assert(debug_view.is_equal("65535"))
 76
 77         debug_view := 0.to_natural_32.bit_not.to_string
 78         assert(debug_view.is_equal("4294967295"))
 79
 80         debug_view := 0.to_natural_64.bit_not.to_string
 81         assert(debug_view.is_equal("18446744073709551615"))
 82
 83         assert(1.to_natural_8.bit_rotate_left(1) = 2.to_natural_8)
 84         assert(1.to_natural_16.bit_rotate_left(1) = 2.to_natural_16)
 85         assert(1.to_natural_32.bit_rotate_left(1) = 2.to_natural_32)
 86         assert(1.to_natural_64.bit_rotate_left(1) = 2.to_natural_64)
 87
 88         assert(1.to_natural_8.bit_rotate(-1) = 2.to_natural_8)
 89         assert(1.to_natural_16.bit_rotate(-1) = 2.to_natural_16)
 90         assert(1.to_natural_32.bit_rotate(-1) = 2.to_natural_32)
 91         assert(1.to_natural_64.bit_rotate(-1) = 2.to_natural_64)
 92
 93         assert(128.to_natural_8.bit_rotate_right(1) = 64.to_natural_8)
 94         assert(128.to_natural_16.bit_rotate_right(1) = 64.to_natural_16)
 95         assert(128.to_natural_32.bit_rotate_right(1) = 64.to_natural_32)
 96         assert(128.to_natural_64.bit_rotate_right(1) = 64.to_natural_64)
 97
 98         assert(128.to_natural_8.bit_rotate(1) = 64.to_natural_8)
 99         assert(128.to_natural_16.bit_rotate(1) = 64.to_natural_16)
100         assert(128.to_natural_32.bit_rotate(1) = 64.to_natural_32)
101         assert(128.to_natural_64.bit_rotate(1) = 64.to_natural_64)
102      end
103end