~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/math/big/rat_test.go

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import (
8
8
        "bytes"
9
9
        "encoding/gob"
 
10
        "encoding/json"
 
11
        "encoding/xml"
10
12
        "fmt"
11
13
        "math"
12
14
        "strconv"
433
435
        }
434
436
}
435
437
 
 
438
var ratNums = []string{
 
439
        "-141592653589793238462643383279502884197169399375105820974944592307816406286",
 
440
        "-1415926535897932384626433832795028841971",
 
441
        "-141592653589793",
 
442
        "-1",
 
443
        "0",
 
444
        "1",
 
445
        "141592653589793",
 
446
        "1415926535897932384626433832795028841971",
 
447
        "141592653589793238462643383279502884197169399375105820974944592307816406286",
 
448
}
 
449
 
 
450
var ratDenoms = []string{
 
451
        "1",
 
452
        "718281828459045",
 
453
        "7182818284590452353602874713526624977572",
 
454
        "718281828459045235360287471352662497757247093699959574966967627724076630353",
 
455
}
 
456
 
 
457
func TestRatJSONEncoding(t *testing.T) {
 
458
        for _, num := range ratNums {
 
459
                for _, denom := range ratDenoms {
 
460
                        var tx Rat
 
461
                        tx.SetString(num + "/" + denom)
 
462
                        b, err := json.Marshal(&tx)
 
463
                        if err != nil {
 
464
                                t.Errorf("marshaling of %s failed: %s", &tx, err)
 
465
                                continue
 
466
                        }
 
467
                        var rx Rat
 
468
                        if err := json.Unmarshal(b, &rx); err != nil {
 
469
                                t.Errorf("unmarshaling of %s failed: %s", &tx, err)
 
470
                                continue
 
471
                        }
 
472
                        if rx.Cmp(&tx) != 0 {
 
473
                                t.Errorf("JSON encoding of %s failed: got %s want %s", &tx, &rx, &tx)
 
474
                        }
 
475
                }
 
476
        }
 
477
}
 
478
 
 
479
func TestRatXMLEncoding(t *testing.T) {
 
480
        for _, num := range ratNums {
 
481
                for _, denom := range ratDenoms {
 
482
                        var tx Rat
 
483
                        tx.SetString(num + "/" + denom)
 
484
                        b, err := xml.Marshal(&tx)
 
485
                        if err != nil {
 
486
                                t.Errorf("marshaling of %s failed: %s", &tx, err)
 
487
                                continue
 
488
                        }
 
489
                        var rx Rat
 
490
                        if err := xml.Unmarshal(b, &rx); err != nil {
 
491
                                t.Errorf("unmarshaling of %s failed: %s", &tx, err)
 
492
                                continue
 
493
                        }
 
494
                        if rx.Cmp(&tx) != 0 {
 
495
                                t.Errorf("XML encoding of %s failed: got %s want %s", &tx, &rx, &tx)
 
496
                        }
 
497
                }
 
498
        }
 
499
}
 
500
 
436
501
func TestIssue2379(t *testing.T) {
437
502
        // 1) no aliasing
438
503
        q := NewRat(3, 2)