GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pythonnet/src/embed_tests/TestPyFloat.cs at master · pythonnet/pythonnet

Expand file tree

/

TestPyFloat.cs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
145 lines (121 loc) · 3.84 KB
/

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);
}
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.