Example #1
0
//reset test
func TestBigAccumulatorReset(t *testing.T) {
	out := bufbig.NewBigAccumulator()

	v := bufbig.NewBigAccumulator()
	v.AddInt(10)
	v.Reset()

	if v.Value().String() != out.Value().String() {
		t.Errorf("Reset() = %v, want %v", v.Value().String(), out.Value().String())
	}
}
Example #2
0
func main() {
	//x := new(bufbig.BigAccumulator)
	x := bufbig.NewBigAccumulator()
	for y := 0; y < 1000000; y++ {
		x.AddInt(1)
	}
	fmt.Println(x.Value())
}
Example #3
0
//setbigint test
func TestBigAccumulatorSetBigInt(t *testing.T) {
	out := big.NewInt(int64(12345))

	v := bufbig.NewBigAccumulator()
	v.SetBigInt(big.NewInt(int64(12345)))

	if v.Value().String() != out.String() {
		t.Errorf("SetBigInt big.NewInt(int64(12345)) = %v, want %v", v.Value().String(), out.String())
	}
}
Example #4
0
//setstring test
func TestBigAccumulatorSetString(t *testing.T) {
	out := big.NewInt(int64(12345654321))

	v := bufbig.NewBigAccumulator()
	v.SetString("12345654321", 10)

	if v.Value().String() != out.String() {
		t.Errorf("SetValue(\"12345654321\",10) = %v, want %v", v.Value().String(), out.String())
	}
}
Example #5
0
//int64 overflow test
func TestBigAccumulatorOverflow(t *testing.T) {
	out, _ := new(big.Int).SetString("9223372036854775808", 10)

	v := bufbig.NewBigAccumulator()
	v.SetString("9223372036854775807", 10)
	v.AddInt(1)

	if v.Value().String() != out.String() {
		t.Errorf("MaxInt64 + 1 = %v, want %v", v.Value().String(), out.String())
	}
}
Example #6
0
//subtraction test
func TestBigAccumulatorSub(t *testing.T) {
	out := big.NewInt(int64(-10))

	v := bufbig.NewBigAccumulator()
	v.AddInt(2)
	v.AddInt(-12)

	if v.Value().String() != out.String() {
		t.Errorf("Subtraction: 2 - 12 = %v, want %v", v.Value().String(), out.String())
	}
}
Example #7
0
//addition test
func TestBigAccumulatorAdd(t *testing.T) {
	out := big.NewInt(int64(10))

	v := bufbig.NewBigAccumulator()
	v.AddInt(2)
	v.AddInt(8)

	if v.Value().String() != out.String() {
		t.Errorf("Addition: 2 + 8 = %v, want %v", v.Value().String(), out.String())
	}
}
Example #8
0
//setstring invalid value test
func TestBigAccumulatorSetStringInvalid(t *testing.T) {
	out := big.NewInt(int64(1))

	v := bufbig.NewBigAccumulator()
	v.AddInt(1)
	res := v.SetString("boobs", 10)

	//expecting SetValue to pass SetString success result back
	if res != false {
		t.Errorf("SetValue Invalid = true, want false")
	}

	//checking to make sure original value persists
	if v.Value().String() != out.String() {
		t.Errorf("SetValue(\"boobs\",10) = %v, want %v", v.Value().String(), out.String())
	}
}