Skip to content

Constructor argument matching supports simple int to (float|double) types #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added method tests for simple promotions int->float, int->double
  • Loading branch information
sigbjorn committed Jul 3, 2016
commit af1b937c6b342bfad304351329265dcf8959237b
18 changes: 18 additions & 0 deletions src/testing/methodtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ public Guid TestStructConversion(Guid v)
{
return v;
}
/// <summary>
/// Method to support testing
/// simple promotion of numeric types:
///
/// integer types -> double
///
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public double TestSimpleIntToDoubleTypePromotion(double a, double b)
{
return a + b;
}
public float TestSimpleIntToFloatTypePromotion(float a, float b)
{
return a + b;
}

public Exception TestSubclassConversion(Exception v)
{
Expand Down
39 changes: 39 additions & 0 deletions src/tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,45 @@ def testMethodCallFlagsConversion(self):
r = object.TestFlagsConversion(flags)
self.assertTrue(r == flags)

def testSimpleTypePromotionIntToDouble(self):
object = MethodTest()
try:
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2,2)
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2.0,2)
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2,2.0)
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2.0,2.0)
self.assertAlmostEqual(sum_of_a_plus_b,2.0+2.0)
except:
self.assertTrue(False,"Type promotion from int to double failed")

try:
should_fail = object.TestSimpleIntToDoubleTypePromotion(2,'2.0')
self.assertTrue(False,"the promotion of string to double should fail")
except:
pass

def testSimpleTypePromotionIntToFloat(self):
object = MethodTest()
try:
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2,2)
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2.0,2)
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2,2.0)
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2.0,2.0)
self.assertAlmostEqual(sum_of_a_plus_b,2.0+2.0)
except:
self.assertTrue(False,"Type promotion from int to float failed")
try:
should_fail = object.TestSimpleIntToDoubleTypePromotion(2,'2.0')
self.assertTrue(False,"the promotion of string to float should fail")
except:
pass

def testMethodCallStructConversion(self):
"""Test struct conversion in method call."""
from System import Guid
Expand Down