Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
6ebf8a64
Commit
6ebf8a64
authored
Jan 30, 2012
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add test of NaN in map
R=iant, r CC=golang-dev
https://golang.org/cl/5576071
parent
deeb1b36
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
2 deletions
+30
-2
map.go
test/map.go
+30
-2
No files found.
test/map.go
View file @
6ebf8a64
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"fmt"
"fmt"
"math"
"math"
"strconv"
"strconv"
"time"
)
)
const
count
=
100
const
count
=
100
...
@@ -27,6 +28,12 @@ func P(a []string) string {
...
@@ -27,6 +28,12 @@ func P(a []string) string {
}
}
func
main
()
{
func
main
()
{
testbasic
()
testfloat
()
testnan
()
}
func
testbasic
()
{
// Test a map literal.
// Test a map literal.
mlit
:=
map
[
string
]
int
{
"0"
:
0
,
"1"
:
1
,
"2"
:
2
,
"3"
:
3
,
"4"
:
4
}
mlit
:=
map
[
string
]
int
{
"0"
:
0
,
"1"
:
1
,
"2"
:
2
,
"3"
:
3
,
"4"
:
4
}
for
i
:=
0
;
i
<
len
(
mlit
);
i
++
{
for
i
:=
0
;
i
<
len
(
mlit
);
i
++
{
...
@@ -489,8 +496,6 @@ func main() {
...
@@ -489,8 +496,6 @@ func main() {
for
_
,
_
=
range
mnil
{
for
_
,
_
=
range
mnil
{
panic
(
"range mnil"
)
panic
(
"range mnil"
)
}
}
testfloat
()
}
}
func
testfloat
()
{
func
testfloat
()
{
...
@@ -646,3 +651,26 @@ func testfloat() {
...
@@ -646,3 +651,26 @@ func testfloat() {
}
}
}
}
}
}
func
testnan
()
{
// Test that NaNs in maps don't go quadratic.
t
:=
func
(
n
int
)
time
.
Duration
{
t0
:=
time
.
Now
()
m
:=
map
[
float64
]
int
{}
nan
:=
math
.
NaN
()
for
i
:=
0
;
i
<
n
;
i
++
{
m
[
nan
]
=
1
}
if
len
(
m
)
!=
n
{
panic
(
"wrong size map after nan insertion"
)
}
return
time
.
Since
(
t0
)
}
n
:=
30000
// 0.02 seconds on a MacBook Air
t1
:=
t
(
n
)
t2
:=
t
(
2
*
n
)
if
t2
>
3
*
t1
{
// should be 2x (linear); allow up to 3x
fmt
.
Printf
(
"too slow: %d inserts: %v; %d inserts: %v
\n
"
,
n
,
t1
,
2
*
n
,
t2
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment