Skip to content

Commit af1b937

Browse files
committed
added method tests for simple promotions int->float, int->double
1 parent 78dca29 commit af1b937

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/testing/methodtest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ public Guid TestStructConversion(Guid v)
7373
{
7474
return v;
7575
}
76+
/// <summary>
77+
/// Method to support testing
78+
/// simple promotion of numeric types:
79+
///
80+
/// integer types -> double
81+
///
82+
/// </summary>
83+
/// <param name="a"></param>
84+
/// <param name="b"></param>
85+
/// <returns></returns>
86+
public double TestSimpleIntToDoubleTypePromotion(double a, double b)
87+
{
88+
return a + b;
89+
}
90+
public float TestSimpleIntToFloatTypePromotion(float a, float b)
91+
{
92+
return a + b;
93+
}
7694

7795
public Exception TestSubclassConversion(Exception v)
7896
{

src/tests/test_method.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,45 @@ def testMethodCallFlagsConversion(self):
208208
r = object.TestFlagsConversion(flags)
209209
self.assertTrue(r == flags)
210210

211+
def testSimpleTypePromotionIntToDouble(self):
212+
object = MethodTest()
213+
try:
214+
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2,2)
215+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
216+
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2.0,2)
217+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
218+
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2,2.0)
219+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
220+
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2.0,2.0)
221+
self.assertAlmostEqual(sum_of_a_plus_b,2.0+2.0)
222+
except:
223+
self.assertTrue(False,"Type promotion from int to double failed")
224+
225+
try:
226+
should_fail = object.TestSimpleIntToDoubleTypePromotion(2,'2.0')
227+
self.assertTrue(False,"the promotion of string to double should fail")
228+
except:
229+
pass
230+
231+
def testSimpleTypePromotionIntToFloat(self):
232+
object = MethodTest()
233+
try:
234+
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2,2)
235+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
236+
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2.0,2)
237+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
238+
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2,2.0)
239+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
240+
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2.0,2.0)
241+
self.assertAlmostEqual(sum_of_a_plus_b,2.0+2.0)
242+
except:
243+
self.assertTrue(False,"Type promotion from int to float failed")
244+
try:
245+
should_fail = object.TestSimpleIntToDoubleTypePromotion(2,'2.0')
246+
self.assertTrue(False,"the promotion of string to float should fail")
247+
except:
248+
pass
249+
211250
def testMethodCallStructConversion(self):
212251
"""Test struct conversion in method call."""
213252
from System import Guid

0 commit comments

Comments
 (0)