MCPcopy
hub / github.com/openacid/slim / TestI16Get

Function TestI16Get

array/int_test.go:791–834  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

789}
790
791func TestI16Get(t *testing.T) {
792 index, eltsData := []int32{}, []int16{}
793 rnd := rand.New(rand.NewSource(time.Now().Unix()))
794
795 keysMap := map[int32]bool{}
796 num, idx, cnt := int32(0), int32(0), int32(1024)
797 for {
798 if rnd.Intn(2) == 1 {
799 index = append(index, idx)
800 eltsData = append(eltsData, int16(rnd.Uint64()))
801 num++
802 keysMap[idx] = true
803 }
804 idx++
805 if num == cnt {
806 break
807 }
808 }
809
810 a, err := array.NewI16(index, eltsData)
811 if err != nil {
812 t.Fatalf("failed new compacted array, err: %s", err)
813 }
814
815 dataIdx := int32(0)
816 for ii := int32(0); ii < idx; ii++ {
817
818 actByte, found := a.Get(ii)
819 _, present := keysMap[ii]
820 if found != present {
821 t.Fatalf("Get i:%d present:%t but:%t", ii, present, found)
822 }
823
824 if found {
825 if eltsData[dataIdx] != actByte {
826 t.Fatalf("Get i:%d is not equal expect: %d, act: %d", ii, eltsData[dataIdx], actByte)
827 }
828 }
829
830 if _, ok := keysMap[ii]; ok {
831 dataIdx++
832 }
833 }
834}
835
836func TestI16EncodeDecode(t *testing.T) {
837

Callers

nothing calls this directly

Calls 2

GetMethod · 0.95
NewI16Function · 0.92

Tested by

no test coverage detected