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

« back to all changes in this revision

Viewing changes to src/pkg/strconv/fp_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import (
8
8
        "bufio"
9
9
        "fmt"
10
 
        "io"
11
10
        "os"
12
11
        "strconv"
13
12
        "strings"
96
95
}
97
96
 
98
97
func TestFp(t *testing.T) {
99
 
        f, err := os.Open("testfp.txt")
 
98
        f, err := os.Open("testdata/testfp.txt")
100
99
        if err != nil {
101
 
                t.Fatal("testfp: open testfp.txt:", err)
 
100
                t.Fatal("testfp: open testdata/testfp.txt:", err)
102
101
        }
103
102
        defer f.Close()
104
103
 
105
 
        b := bufio.NewReader(f)
 
104
        s := bufio.NewScanner(f)
106
105
 
107
 
        lineno := 0
108
 
        for {
109
 
                line, err2 := b.ReadString('\n')
110
 
                if err2 == io.EOF {
111
 
                        break
112
 
                }
113
 
                if err2 != nil {
114
 
                        t.Fatal("testfp: read testfp.txt: " + err2.Error())
115
 
                }
116
 
                line = line[0 : len(line)-1]
117
 
                lineno++
 
106
        for lineno := 1; s.Scan(); lineno++ {
 
107
                line := s.Text()
118
108
                if len(line) == 0 || line[0] == '#' {
119
109
                        continue
120
110
                }
121
111
                a := strings.Split(line, " ")
122
112
                if len(a) != 4 {
123
 
                        t.Error("testfp.txt:", lineno, ": wrong field count")
 
113
                        t.Error("testdata/testfp.txt:", lineno, ": wrong field count")
124
114
                        continue
125
115
                }
126
116
                var s string
130
120
                        var ok bool
131
121
                        v, ok = myatof64(a[2])
132
122
                        if !ok {
133
 
                                t.Error("testfp.txt:", lineno, ": cannot atof64 ", a[2])
 
123
                                t.Error("testdata/testfp.txt:", lineno, ": cannot atof64 ", a[2])
134
124
                                continue
135
125
                        }
136
126
                        s = fmt.Sprintf(a[1], v)
137
127
                case "float32":
138
128
                        v1, ok := myatof32(a[2])
139
129
                        if !ok {
140
 
                                t.Error("testfp.txt:", lineno, ": cannot atof32 ", a[2])
 
130
                                t.Error("testdata/testfp.txt:", lineno, ": cannot atof32 ", a[2])
141
131
                                continue
142
132
                        }
143
133
                        s = fmt.Sprintf(a[1], v1)
144
134
                        v = float64(v1)
145
135
                }
146
136
                if s != a[3] {
147
 
                        t.Error("testfp.txt:", lineno, ": ", a[0], " ", a[1], " ", a[2], " (", v, ") ",
 
137
                        t.Error("testdata/testfp.txt:", lineno, ": ", a[0], " ", a[1], " ", a[2], " (", v, ") ",
148
138
                                "want ", a[3], " got ", s)
149
139
                }
150
140
        }
 
141
        if s.Err() != nil {
 
142
                t.Fatal("testfp: read testdata/testfp.txt: ", s.Err())
 
143
        }
151
144
}