FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/src/test/java/com/jsoniter/TestFloat.java at master · rubythonode/java · GitHub
rubythonode
/
java
Public
forked from
json-iterator/java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
java
/
src
/
test
/
java
/
com
/
jsoniter
/
TestFloat.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (48 loc) · 2.16 KB
Breadcrumbs
java
/
src
/
test
/
java
/
com
/
jsoniter
/
TestFloat.java
Copy path
File metadata and controls
57 lines (48 loc) · 2.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package
com
.
jsoniter
;
import
junit
.
framework
.
TestCase
;
import
org
.
junit
.
experimental
.
categories
.
Category
;
import
java
.
io
.
ByteArrayInputStream
;
import
java
.
io
.
IOException
;
public
class
TestFloat
extends
TestCase
{
private
boolean
isStreaming
;
public
void
test_positive_negative
()
throws
IOException
{
// positive
assertEquals
(
12.3f
,
parseFloat
(
"12.3,"
));
assertEquals
(
12.3d
,
parseDouble
(
"12.3,"
));
// negative
assertEquals
(-
12.3f
,
parseFloat
(
"-12.3,"
));
assertEquals
(-
12.3d
,
parseDouble
(
"-12.3,"
));
}
public
void
test_decimal_places
()
throws
IOException
{
assertEquals
(
Long
.
MAX_VALUE
,
parseFloat
(
"9223372036854775807,"
),
0.01f
);
assertEquals
(
Long
.
MAX_VALUE
,
parseDouble
(
"9223372036854775807,"
),
0.01f
);
assertEquals
(
9923372036854775807f
,
parseFloat
(
"9923372036854775807,"
),
0.01f
);
assertEquals
(
9923372036854775807d
,
parseDouble
(
"9923372036854775807,"
),
0.01f
);
assertEquals
(
720368.54775807f
,
parseFloat
(
"720368.54775807,"
),
0.01f
);
assertEquals
(
720368.54775807d
,
parseDouble
(
"720368.54775807,"
),
0.01f
);
assertEquals
(
72036.854775807f
,
parseFloat
(
"72036.854775807,"
),
0.01f
);
assertEquals
(
72036.854775807d
,
parseDouble
(
"72036.854775807,"
),
0.01f
);
assertEquals
(
720368.54775807f
,
parseFloat
(
"720368.547758075,"
),
0.01f
);
assertEquals
(
720368.54775807d
,
parseDouble
(
"720368.547758075,"
),
0.01f
);
}
@
Category
(
StreamingCategory
.
class
)
public
void
test_streaming
()
throws
IOException
{
isStreaming
=
true
;
test_positive_negative
();
test_decimal_places
();
}
private
float
parseFloat
(
String
input
)
throws
IOException
{
if
(
isStreaming
) {
return
JsonIterator
.
parse
(
new
ByteArrayInputStream
(
input
.
getBytes
()),
2
).
readFloat
();
}
else
{
return
JsonIterator
.
parse
(
input
).
readFloat
();
}
}
private
double
parseDouble
(
String
input
)
throws
IOException
{
if
(
isStreaming
) {
return
JsonIterator
.
parse
(
new
ByteArrayInputStream
(
input
.
getBytes
()),
2
).
readDouble
();
}
else
{
return
JsonIterator
.
parse
(
input
).
readDouble
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL