github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/uint256/conversion_test.gno (about) 1 package uint256 2 3 import ( 4 "testing" 5 ) 6 7 func TestIsUint64(t *testing.T) { 8 tests := []struct { 9 x string 10 want bool 11 }{ 12 {"0x0", true}, 13 {"0x1", true}, 14 {"0x10", true}, 15 {"0xffffffffffffffff", true}, 16 {"0x10000000000000000", false}, 17 } 18 19 for _, tc := range tests { 20 x := MustFromHex(tc.x) 21 got := x.IsUint64() 22 23 if got != tc.want { 24 t.Errorf("IsUint64(%s) = %v, want %v", tc.x, got, tc.want) 25 } 26 } 27 } 28 29 func TestDec(t *testing.T) { 30 testCases := []struct { 31 name string 32 z Uint 33 want string 34 }{ 35 { 36 name: "zero", 37 z: Uint{arr: [4]uint64{0, 0, 0, 0}}, 38 want: "0", 39 }, 40 { 41 name: "less than 20 digits", 42 z: Uint{arr: [4]uint64{1234567890, 0, 0, 0}}, 43 want: "1234567890", 44 }, 45 { 46 name: "max possible value", 47 z: Uint{arr: [4]uint64{^uint64(0), ^uint64(0), ^uint64(0), ^uint64(0)}}, 48 want: "115792089237316195423570985008687907853269984665640564039457584007913129639935", 49 }, 50 } 51 52 for _, tc := range testCases { 53 t.Run(tc.name, func(t *testing.T) { 54 result := tc.z.Dec() 55 if result != tc.want { 56 t.Errorf("Dec(%v) = %s, want %s", tc.z, result, tc.want) 57 } 58 }) 59 } 60 }