| 2432 | } |
| 2433 | |
| 2434 | func TestBigIntSetString(t *testing.T) { |
| 2435 | tmp := new(BigInt) |
| 2436 | for i, test := range stringTests { |
| 2437 | // initialize to a non-zero value so that issues with parsing |
| 2438 | // 0 are detected |
| 2439 | tmp.SetInt64(1234567890) |
| 2440 | n1, ok1 := new(BigInt).SetString(test.in, test.base) |
| 2441 | n2, ok2 := tmp.SetString(test.in, test.base) |
| 2442 | expected := NewBigInt(test.val) |
| 2443 | if ok1 != test.ok || ok2 != test.ok { |
| 2444 | t.Errorf("#%d (input '%s') ok incorrect (should be %t)", i, test.in, test.ok) |
| 2445 | continue |
| 2446 | } |
| 2447 | if !ok1 { |
| 2448 | if n1 != nil { |
| 2449 | t.Errorf("#%d (input '%s') n1 != nil", i, test.in) |
| 2450 | } |
| 2451 | continue |
| 2452 | } |
| 2453 | if !ok2 { |
| 2454 | if n2 != nil { |
| 2455 | t.Errorf("#%d (input '%s') n2 != nil", i, test.in) |
| 2456 | } |
| 2457 | continue |
| 2458 | } |
| 2459 | |
| 2460 | if n1.Cmp(expected) != 0 { |
| 2461 | t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n1, test.val) |
| 2462 | } |
| 2463 | if n2.Cmp(expected) != 0 { |
| 2464 | t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n2, test.val) |
| 2465 | } |
| 2466 | } |
| 2467 | } |
| 2468 | |
| 2469 | var formatTests = []struct { |
| 2470 | input string |