-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflint_fmpq_test.go
81 lines (63 loc) · 1.58 KB
/
flint_fmpq_test.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package goflint
import "testing"
// TestNewFmpq tests assigning rationals and that the Stringer for the Fmpq type works
func TestNewFmpq(t *testing.T) {
a := NewFmpq(3, 2)
b := a.String()
expected := "3/2"
if b != expected {
t.Errorf("Expected %v but got %v", expected, b)
}
}
// TestSetFmpqFraction tests that assigning rationals with Fmpz numerators and denominators
// works as expected.
func TestSetFmpqFraction(t *testing.T) {
a := NewFmpz(3)
b := NewFmpz(2)
c := new(Fmpq)
c.SetFmpqFraction(a, b)
s := c.String()
expected := "3/2"
if s != expected {
t.Errorf("Expected %s but got %s", expected, s)
}
}
func TestCmpRational(t *testing.T) {
a := NewFmpq(2, 3)
b := NewFmpq(2, 3)
c := NewFmpq(5, 3)
if a.CmpRational(b) != 0 {
t.Error("Expected a.CmpRational(b) == 0 but it wasnt.")
}
if a.CmpRational(c) > 0 {
t.Error("Expected a.CmpRational(c) < 0 (i.e. a < c) but it wasnt.")
}
if c.CmpRational(a) < 0 {
t.Error("Expected c.CmpRational(a) > 0 (i.e. a > c) but it wasnt.")
}
}
func TestGetFmpqFraction(t *testing.T) {
a := 3
b := 2
c := new(Fmpq).SetFmpqFraction(NewFmpz(int64(a)), NewFmpz(int64(b)))
num, den := c.GetFmpqFraction()
if a != num || b != den {
t.Errorf("GetFmpqFraction: want / got mismatched %d/%d but got %d/%d", a, b, num, den)
}
}
func TestNumRef(t *testing.T) {
a := NewFmpq(1, 3)
want := 1
got := a.NumRef()
if got != want {
t.Errorf("NumRef: got %v want %v", got, want)
}
}
func TestDenRef(t *testing.T) {
a := NewFmpq(1, 3)
want := 3
got := a.DenRef()
if got != want {
t.Errorf("DenRef: got %v want %v", got, want)
}
}