github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/isc/test/number_test.go (about) 1 package test 2 3 import ( 4 "strconv" 5 "testing" 6 7 . "github.com/isyscore/isc-gobase/isc" 8 ) 9 10 func TestNumber(t *testing.T) { 11 i := ISCInt(1) 12 iarr := i.RangeTo(10) 13 iarr.ForEach(func(i int) { 14 t.Logf("%d\n", i) 15 }) 16 17 iarr2 := i.RangeStepTo(10, 2) 18 iarr2.ForEach(func(i int) { 19 t.Logf("%d\n", i) 20 }) 21 22 ii := ISCInt(10) 23 iiarr := ii.DownTo(0) 24 iiarr.ForEach(func(i int) { 25 t.Logf("%d\n", i) 26 }) 27 } 28 29 func TestRotate(t *testing.T) { 30 a, b := ISCInt(1), ISCInt(8) 31 s := strconv.IntSize 32 t.Logf("int size = %d", strconv.IntSize) 33 34 ii := a << 1 35 iii := a >> (s - 1) 36 37 // iii := a >> -1 38 t.Logf("%d\n", ii) 39 t.Logf("%d\n", iii) 40 t.Logf("%d\n", ii|iii) 41 // return ISCInt(uint((int(i) << bitCount)) | (uint(i) >> -bitCount)) 42 43 t.Logf("%d\n", a.RotateLeft(1)) 44 t.Logf("%d\n", a.RotateLeft(2)) 45 t.Logf("%d\n", b.RotateRight(1)) 46 t.Logf("%d\n", b.RotateRight(2)) 47 } 48 49 func TestRadix(t *testing.T) { 50 a := ISCInt(109) 51 t.Logf("%s\n", a.ToHex()) 52 t.Logf("%s\n", a.ToOct()) 53 t.Logf("%s\n", a.ToBinary()) 54 55 b := ISCString("6D") 56 i, _ := b.ToIntRadix(16) 57 t.Logf("%d\n", i) 58 59 } 60 61 func TestRune(t *testing.T) { 62 c := ISCChar('青') 63 t.Logf("%d\n", c.Code()) 64 65 c2 := ISCChar(38738) 66 t.Logf("%s\n", c2.ToString()) 67 } 68 69 func TestForRange(t *testing.T) { 70 for idx, e := range ISCInt(0).RangeStepTo(10, 2) { 71 t.Logf("%d %d\n", idx, e) 72 } 73 }