summaryrefslogtreecommitdiffstats
path: root/lib/cbrt_test.go
blob: 6b3c9f34ba24b1babccf018f12e319e86abe5226 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright © 2021 siddharth ravikumar <s@ricketyspace.net>
// SPDX-License-Identifier: ISC

package lib

import (
	"math/big"
	"testing"
)

func TestBigCubeRoot(t *testing.T) {
	a := big.NewFloat(612)
	acr := BigCubeRoot(a)
	if acr == nil {
		t.Errorf("Could not find cube root of %v\n", a)
		return
	}
	expected := big.NewFloat(8.490184748)
	if big.NewFloat(0).Sub(acr, expected).Cmp(bigCubeRootTolerance) != -1 {
		t.Errorf("Could not find cube root of %v (%v)\n", a, acr)
		return
	}
}

func TestBigIntCubeRoot(t *testing.T) {
	a := big.NewInt(19683)
	acr := BigIntCubeRoot(a)
	if acr == nil {
		t.Errorf("Could not find cube root of %v\n", a)
		return
	}
	expected := big.NewInt(27)
	if big.NewInt(0).Sub(acr, expected).Cmp(big.NewInt(0)) != 0 {
		t.Errorf("Could not find cube root of %v (%v)\n", a, acr)
		return
	}
}