@@ -881,32 +881,27 @@ func TestSRsh(t *testing.T) {
881881}
882882
883883func TestByte (t * testing.T ) {
884- z := new (Int ).SetBytes (hex2Bytes ("ABCDEF09080706050403020100000000000000000000000000000000000000ef" ))
885- actual := z .Byte (NewInt (0 ))
886- expected := new (Int ).SetBytes (hex2Bytes ("00000000000000000000000000000000000000000000000000000000000000ab" ))
887- if ! actual .Eq (expected ) {
888- t .Fatalf ("Expected %x, got %x" , expected , actual )
889- }
890-
891- z = new (Int ).SetBytes (hex2Bytes ("ABCDEF09080706050403020100000000000000000000000000000000000000ef" ))
892- actual = z .Byte (NewInt (31 ))
893- expected = new (Int ).SetBytes (hex2Bytes ("00000000000000000000000000000000000000000000000000000000000000ef" ))
894- if ! actual .Eq (expected ) {
895- t .Fatalf ("Expected %x, got %x" , expected , actual )
896- }
897-
898- z = new (Int ).SetBytes (hex2Bytes ("ABCDEF09080706050403020100000000000000000000000000000000000000ef" ))
899- actual = z .Byte (NewInt (32 ))
900- expected = new (Int ).SetBytes (hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000000" ))
901- if ! actual .Eq (expected ) {
902- t .Fatalf ("Expected %x, got %x" , expected , actual )
903- }
904-
905- z = new (Int ).SetBytes (hex2Bytes ("ABCDEF0908070605040302011111111111111111111111111111111111111111" ))
906- actual = z .Byte (new (Int ).SetBytes (hex2Bytes ("f000000000000000000000000000000000000000000000000000000000000001" )))
907- expected = new (Int ).SetBytes (hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000000" ))
908- if ! actual .Eq (expected ) {
909- t .Fatalf ("Expected %x, got %x" , expected , actual )
884+ input , err := FromHex ("0x102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" )
885+ if err != nil {
886+ t .Fatal (err )
887+ }
888+ for i := uint64 (0 ); i < 35 ; i ++ {
889+ var (
890+ z = input .Clone ()
891+ index = NewInt (i )
892+ have = z .Byte (index )
893+ want = NewInt (i )
894+ )
895+ if i >= 32 {
896+ want .Clear ()
897+ }
898+ if ! have .Eq (want ) {
899+ t .Fatalf ("index %d: have %#x want %#x" , i , have , want )
900+ }
901+ // Also check that we indeed modified the z
902+ if z != have {
903+ t .Fatalf ("index %d: should return self %v %v" , i , z , have )
904+ }
910905 }
911906}
912907
0 commit comments