Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(171)

Unified Diff: src/pkg/big/int_test.go

Issue 4715041: code review 4715041: go/printer: changed max. number of newlines from 3 to 2 (Closed)
Patch Set: diff -r 43f78423340b https://go.googlecode.com/hg/ Created 13 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/big/int.go ('k') | src/pkg/big/nat.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/big/int_test.go
===================================================================
--- a/src/pkg/big/int_test.go
+++ b/src/pkg/big/int_test.go
@@ -13,7 +13,6 @@
"testing/quick"
)
-
func isNormalized(x *Int) bool {
if len(x.abs) == 0 {
return !x.neg
@@ -22,13 +21,11 @@
return x.abs[len(x.abs)-1] != 0
}
-
type funZZ func(z, x, y *Int) *Int
type argZZ struct {
z, x, y *Int
}
-
var sumZZ = []argZZ{
{NewInt(0), NewInt(0), NewInt(0)},
{NewInt(1), NewInt(1), NewInt(0)},
@@ -38,7 +35,6 @@
{NewInt(-1111111110), NewInt(-123456789), NewInt(-987654321)},
}
-
var prodZZ = []argZZ{
{NewInt(0), NewInt(0), NewInt(0)},
{NewInt(0), NewInt(1), NewInt(0)},
@@ -47,7 +43,6 @@
// TODO(gri) add larger products
}
-
func TestSignZ(t *testing.T) {
var zero Int
for _, a := range sumZZ {
@@ -59,7 +54,6 @@
}
}
-
func TestSetZ(t *testing.T) {
for _, a := range sumZZ {
var z Int
@@ -73,7 +67,6 @@
}
}
-
func TestAbsZ(t *testing.T) {
var zero Int
for _, a := range sumZZ {
@@ -90,7 +83,6 @@
}
}
-
func testFunZZ(t *testing.T, msg string, f funZZ, a argZZ) {
var z Int
f(&z, a.x, a.y)
@@ -102,7 +94,6 @@
}
}
-
func TestSumZZ(t *testing.T) {
AddZZ := func(z, x, y *Int) *Int { return z.Add(x, y) }
SubZZ := func(z, x, y *Int) *Int { return z.Sub(x, y) }
@@ -121,7 +112,6 @@
}
}
-
func TestProdZZ(t *testing.T) {
MulZZ := func(z, x, y *Int) *Int { return z.Mul(x, y) }
for _, a := range prodZZ {
@@ -133,7 +123,6 @@
}
}
-
// mulBytes returns x*y via grade school multiplication. Both inputs
// and the result are assumed to be in big-endian representation (to
// match the semantics of Int.Bytes and Int.SetBytes).
@@ -166,7 +155,6 @@
return z[i:]
}
-
func checkMul(a, b []byte) bool {
var x, y, z1 Int
x.SetBytes(a)
@@ -179,14 +167,12 @@
return z1.Cmp(&z2) == 0
}
-
func TestMul(t *testing.T) {
if err := quick.Check(checkMul, nil); err != nil {
t.Error(err)
}
}
-
var mulRangesZ = []struct {
a, b int64
prod string
@@ -212,7 +198,6 @@
},
}
-
func TestMulRangeZ(t *testing.T) {
var tmp Int
// test entirely positive ranges
@@ -231,7 +216,6 @@
}
}
-
var stringTests = []struct {
in string
out string
@@ -280,7 +264,6 @@
{"1001010111", "1001010111", 2, 0x257, true},
}
-
func format(base int) string {
switch base {
case 2:
@@ -293,7 +276,6 @@
return "%d"
}
-
func TestGetString(t *testing.T) {
z := new(Int)
for i, test := range stringTests {
@@ -316,7 +298,6 @@
}
}
-
func TestSetString(t *testing.T) {
tmp := new(Int)
for i, test := range stringTests {
@@ -347,7 +328,6 @@
}
}
-
var formatTests = []struct {
input string
format string
@@ -407,7 +387,6 @@
"12 49 ad 25 94 c3 7c eb 0b 27 84 c4 ce 0b f3 8a ce 40 8e 21 1a 7c aa b2 43 08 a8 2e 8f 10 00 00 00 00 00 00 00 00 00 00 00 00"},
}
-
func TestFormat(t *testing.T) {
for i, test := range formatTests {
var x *Int
@@ -425,7 +404,6 @@
}
}
-
var scanTests = []struct {
input string
format string
@@ -449,7 +427,6 @@
{"0XABC 12", "%v", "2748", 3},
}
-
func TestScan(t *testing.T) {
var buf bytes.Buffer
for i, test := range scanTests {
@@ -468,7 +445,6 @@
}
}
-
// Examples from the Go Language Spec, section "Arithmetic operators"
var divisionSignsTests = []struct {
x, y int64
@@ -483,7 +459,6 @@
{8, 4, 2, 0, 2, 0},
}
-
func TestDivisionSigns(t *testing.T) {
for i, test := range divisionSignsTests {
x := NewInt(test.x)
@@ -541,7 +516,6 @@
}
}
-
func checkSetBytes(b []byte) bool {
hex1 := hex.EncodeToString(new(Int).SetBytes(b).Bytes())
hex2 := hex.EncodeToString(b)
@@ -557,27 +531,23 @@
return hex1 == hex2
}
-
func TestSetBytes(t *testing.T) {
if err := quick.Check(checkSetBytes, nil); err != nil {
t.Error(err)
}
}
-
func checkBytes(b []byte) bool {
b2 := new(Int).SetBytes(b).Bytes()
return bytes.Compare(b, b2) == 0
}
-
func TestBytes(t *testing.T) {
if err := quick.Check(checkSetBytes, nil); err != nil {
t.Error(err)
}
}
-
func checkQuo(x, y []byte) bool {
u := new(Int).SetBytes(x)
v := new(Int).SetBytes(y)
@@ -600,7 +570,6 @@
return uprime.Cmp(u) == 0
}
-
var quoTests = []struct {
x, y string
q, r string
@@ -619,7 +588,6 @@
},
}
-
func TestQuo(t *testing.T) {
if err := quick.Check(checkQuo, nil); err != nil {
t.Error(err)
@@ -640,7 +608,6 @@
}
}
-
func TestQuoStepD6(t *testing.T) {
// See Knuth, Volume 2, section 4.3.1, exercise 21. This code exercises
// a code path which only triggers 1 in 10^{-19} cases.
@@ -660,7 +627,6 @@
}
}
-
var bitLenTests = []struct {
in string
out int
@@ -679,7 +645,6 @@
{"-0x4000000000000000000000", 87},
}
-
func TestBitLen(t *testing.T) {
for i, test := range bitLenTests {
x, ok := new(Int).SetString(test.in, 0)
@@ -694,7 +659,6 @@
}
}
-
var expTests = []struct {
x, y, m string
out string
@@ -719,7 +683,6 @@
},
}
-
func TestExp(t *testing.T) {
for i, test := range expTests {
x, ok1 := new(Int).SetString(test.x, 0)
@@ -750,7 +713,6 @@
}
}
-
func checkGcd(aBytes, bBytes []byte) bool {
a := new(Int).SetBytes(aBytes)
b := new(Int).SetBytes(bBytes)
@@ -767,7 +729,6 @@
return x.Cmp(d) == 0
}
-
var gcdTests = []struct {
a, b int64
d, x, y int64
@@ -775,7 +736,6 @@
{120, 23, 1, -9, 47},
}
-
func TestGcd(t *testing.T) {
for i, test := range gcdTests {
a := NewInt(test.a)
@@ -801,7 +761,6 @@
quick.Check(checkGcd, nil)
}
-
var primes = []string{
"2",
"3",
@@ -827,7 +786,6 @@
"203956878356401977405765866929034577280193993314348263094772646453283062722701277632936616063144088173312372882677123879538709400158306567338328279154499698366071906766440037074217117805690872792848149112022286332144876183376326512083574821647933992961249917319836219304274280243803104015000563790123",
}
-
var composites = []string{
"21284175091214687912771199898307297748211672914763848041968395774954376176754",
"6084766654921918907427900243509372380954290099172559290432744450051395395951",
@@ -835,7 +793,6 @@
"82793403787388584738507275144194252681",
}
-
func TestProbablyPrime(t *testing.T) {
nreps := 20
if testing.Short() {
@@ -859,14 +816,12 @@
}
}
-
type intShiftTest struct {
in string
shift uint
out string
}
-
var rshTests = []intShiftTest{
{"0", 0, "0"},
{"-0", 0, "0"},
@@ -894,7 +849,6 @@
{"340282366920938463463374607431768211456", 128, "1"},
}
-
func TestRsh(t *testing.T) {
for i, test := range rshTests {
in, _ := new(Int).SetString(test.in, 10)
@@ -910,7 +864,6 @@
}
}
-
func TestRshSelf(t *testing.T) {
for i, test := range rshTests {
z, _ := new(Int).SetString(test.in, 10)
@@ -926,7 +879,6 @@
}
}
-
var lshTests = []intShiftTest{
{"0", 0, "0"},
{"0", 1, "0"},
@@ -949,7 +901,6 @@
{"1", 128, "340282366920938463463374607431768211456"},
}
-
func TestLsh(t *testing.T) {
for i, test := range lshTests {
in, _ := new(Int).SetString(test.in, 10)
@@ -965,7 +916,6 @@
}
}
-
func TestLshSelf(t *testing.T) {
for i, test := range lshTests {
z, _ := new(Int).SetString(test.in, 10)
@@ -981,7 +931,6 @@
}
}
-
func TestLshRsh(t *testing.T) {
for i, test := range rshTests {
in, _ := new(Int).SetString(test.in, 10)
@@ -1009,7 +958,6 @@
}
}
-
var int64Tests = []int64{
0,
1,
@@ -1023,7 +971,6 @@
-9223372036854775808,
}
-
func TestInt64(t *testing.T) {
for i, testVal := range int64Tests {
in := NewInt(testVal)
@@ -1035,7 +982,6 @@
}
}
-
var bitwiseTests = []struct {
x, y string
and, or, xor, andNot string
@@ -1079,7 +1025,6 @@
},
}
-
type bitFun func(z, x, y *Int) *Int
func testBitFun(t *testing.T, msg string, f bitFun, x, y *Int, exp string) {
@@ -1092,7 +1037,6 @@
}
}
-
func testBitFunSelf(t *testing.T, msg string, f bitFun, x, y *Int, exp string) {
self := new(Int)
self.Set(x)
@@ -1105,7 +1049,6 @@
}
}
-
func altBit(x *Int, i int) uint {
z := new(Int).Rsh(x, uint(i))
z = z.And(z, NewInt(1))
@@ -1115,7 +1058,6 @@
return 0
}
-
func altSetBit(z *Int, x *Int, i int, b uint) *Int {
one := NewInt(1)
m := one.Lsh(one, uint(i))
@@ -1128,7 +1070,6 @@
panic("set bit is not 0 or 1")
}
-
func testBitset(t *testing.T, x *Int) {
n := x.BitLen()
z := new(Int).Set(x)
@@ -1166,7 +1107,6 @@
}
}
-
var bitsetTests = []struct {
x string
i int
@@ -1186,7 +1126,6 @@
{"-0x2000000000000000000000000001", 110, 1},
}
-
func TestBitSet(t *testing.T) {
for _, test := range bitwiseTests {
x := new(Int)
@@ -1207,7 +1146,6 @@
}
}
-
func BenchmarkBitset(b *testing.B) {
z := new(Int)
z.SetBit(z, 512, 1)
@@ -1218,7 +1156,6 @@
}
}
-
func BenchmarkBitsetNeg(b *testing.B) {
z := NewInt(-1)
z.SetBit(z, 512, 0)
@@ -1229,7 +1166,6 @@
}
}
-
func BenchmarkBitsetOrig(b *testing.B) {
z := new(Int)
altSetBit(z, z, 512, 1)
@@ -1240,7 +1176,6 @@
}
}
-
func BenchmarkBitsetNegOrig(b *testing.B) {
z := NewInt(-1)
altSetBit(z, z, 512, 0)
@@ -1251,7 +1186,6 @@
}
}
-
func TestBitwise(t *testing.T) {
x := new(Int)
y := new(Int)
@@ -1270,7 +1204,6 @@
}
}
-
var notTests = []struct {
in string
out string
@@ -1286,7 +1219,6 @@
},
}
-
func TestNot(t *testing.T) {
in := new(Int)
out := new(Int)
@@ -1305,7 +1237,6 @@
}
}
-
var modInverseTests = []struct {
element string
prime string
@@ -1315,7 +1246,6 @@
{"239487239847", "2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919"},
}
-
func TestModInverse(t *testing.T) {
var element, prime Int
one := NewInt(1)
@@ -1331,7 +1261,6 @@
}
}
-
// used by TestIntGobEncoding and TestRatGobEncoding
var gobEncodingTests = []string{
"0",
« no previous file with comments | « src/pkg/big/int.go ('k') | src/pkg/big/nat.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b