FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/embed_tests/TestPyFloat.cs at v3.1.0 · pythonnet/pythonnet · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
pythonnet
/
pythonnet
Public
Notifications
You must be signed in to change notification settings
Fork
780
Star
5.5k
Code
Issues
153
Pull requests
12
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
TestPyFloat.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
145 lines (121 loc) · 3.84 KB
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
TestPyFloat.cs
Copy path
File metadata and controls
145 lines (121 loc) · 3.84 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using
System
;
using
NUnit
.
Framework
;
using
Python
.
Runtime
;
namespace
Python
.
EmbeddingTest
{
/// <remarks>
/// PyFloat implementation isn't complete, thus tests aren't complete.
/// </remarks>
public
class
TestPyFloat
{
[
Test
]
public
void
FloatCtor
(
)
{
const
float
a
=
4.5F
;
var
i
=
new
PyFloat
(
a
)
;
Assert
.
True
(
PyFloat
.
IsFloatType
(
i
)
)
;
// Assert.Assert.That(a.ToInt32(), Is.EqualTo(i));
}
[
Test
]
public
void
PyObjectCtorGood
(
)
{
var
i
=
new
PyFloat
(
5
)
;
var
a
=
new
PyFloat
(
i
)
;
Assert
.
True
(
PyFloat
.
IsFloatType
(
a
)
)
;
// Assert.Assert.That(a.ToInt32(), Is.EqualTo(i));
}
[
Test
]
public
void
PyObjectCtorBad
(
)
{
var
i
=
new
PyString
(
"Foo"
)
;
PyFloat
a
=
null
;
var
ex
=
Assert
.
Throws
<
ArgumentException
>
(
(
)
=>
a
=
new
PyFloat
(
i
)
)
;
StringAssert
.
StartsWith
(
"object is not a float"
,
ex
.
Message
)
;
Assert
.
IsNull
(
a
)
;
}
[
Test
]
public
void
DoubleCtor
(
)
{
const
double
a
=
4.5
;
var
i
=
new
PyFloat
(
a
)
;
Assert
.
True
(
PyFloat
.
IsFloatType
(
i
)
)
;
// Assert.Assert.That(a.ToInt32(), Is.EqualTo(i));
}
[
Test
]
public
void
StringIntCtor
(
)
{
const
string
a
=
"5"
;
var
i
=
new
PyFloat
(
a
)
;
Assert
.
True
(
PyFloat
.
IsFloatType
(
i
)
)
;
// Assert.Assert.That(a.ToInt32(), Is.EqualTo(i));
}
[
Test
]
public
void
StringDoubleCtor
(
)
{
const
string
a
=
"4.5"
;
var
i
=
new
PyFloat
(
a
)
;
Assert
.
True
(
PyFloat
.
IsFloatType
(
i
)
)
;
// Assert.Assert.That(a.ToInt32(), Is.EqualTo(i));
}
[
Test
]
public
void
StringBadCtor
(
)
{
const
string
i
=
"Foo"
;
PyFloat
a
=
null
;
var
ex
=
Assert
.
Throws
<
PythonException
>
(
(
)
=>
a
=
new
PyFloat
(
i
)
)
;
StringAssert
.
StartsWith
(
"could not convert string to float"
,
ex
.
Message
)
;
Assert
.
IsNull
(
a
)
;
}
[
Test
]
public
void
IsFloatTrue
(
)
{
const
double
a
=
4.5
;
var
i
=
new
PyFloat
(
a
)
;
Assert
.
True
(
PyFloat
.
IsFloatType
(
i
)
)
;
}
[
Test
]
public
void
IsFloatFalse
(
)
{
var
i
=
new
PyString
(
"Foo"
)
;
Assert
.
False
(
PyFloat
.
IsFloatType
(
i
)
)
;
}
[
Test
]
public
void
AsFloatGood
(
)
{
const
double
a
=
4.5
;
var
i
=
new
PyFloat
(
a
)
;
PyFloat
s
=
PyFloat
.
AsFloat
(
i
)
;
Assert
.
True
(
PyFloat
.
IsFloatType
(
s
)
)
;
// Assert.Assert.That(a.ToInt32(), Is.EqualTo(i));
}
[
Test
]
public
void
AsFloatBad
(
)
{
var
s
=
new
PyString
(
"Foo"
)
;
PyFloat
a
=
null
;
var
ex
=
Assert
.
Throws
<
PythonException
>
(
(
)
=>
a
=
PyFloat
.
AsFloat
(
s
)
)
;
StringAssert
.
StartsWith
(
"could not convert string to float"
,
ex
.
Message
)
;
Assert
.
IsNull
(
a
)
;
}
[
Test
]
public
void
CompareTo
(
)
{
var
v
=
new
PyFloat
(
42
)
;
Assert
.
That
(
v
.
CompareTo
(
42f
)
,
Is
.
EqualTo
(
0
)
)
;
Assert
.
That
(
v
.
CompareTo
(
42d
)
,
Is
.
EqualTo
(
0
)
)
;
Assert
.
That
(
v
.
CompareTo
(
41f
)
,
Is
.
EqualTo
(
1
)
)
;
Assert
.
That
(
v
.
CompareTo
(
41d
)
,
Is
.
EqualTo
(
1
)
)
;
Assert
.
That
(
v
.
CompareTo
(
43f
)
,
Is
.
EqualTo
(
-
1
)
)
;
Assert
.
That
(
v
.
CompareTo
(
43d
)
,
Is
.
EqualTo
(
-
1
)
)
;
}
[
Test
]
public
void
Equals
(
)
{
var
v
=
new
PyFloat
(
42
)
;
Assert
.
That
(
v
.
Equals
(
42f
)
,
Is
.
True
)
;
Assert
.
That
(
v
.
Equals
(
42d
)
,
Is
.
True
)
;
Assert
.
That
(
v
.
Equals
(
41f
)
,
Is
.
False
)
;
Assert
.
That
(
v
.
Equals
(
41d
)
,
Is
.
False
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL