Skip to content

Commit

Permalink
#190 - mul tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Sep 25, 2017
1 parent 4715ef8 commit 35961b7
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 8 deletions.
36 changes: 28 additions & 8 deletions xFunc.Maths/Analyzers/TypeAnalyzers/TypeAnalyzer.cs
Expand Up @@ -483,27 +483,47 @@ public virtual ResultType Analyze(Mul exp)
if (leftResult == ResultType.Undefined || rightResult == ResultType.Undefined)
return ResultType.Undefined;

if (leftResult == ResultType.Number && rightResult == ResultType.Number)
return ResultType.Number;
if (leftResult == ResultType.ComplexNumber)
{
if (rightResult == ResultType.ComplexNumber || rightResult == ResultType.Number)
return ResultType.ComplexNumber;

if (leftResult == ResultType.ComplexNumber && (rightResult == ResultType.ComplexNumber || rightResult == ResultType.Number))
return ResultType.ComplexNumber;
throw new BinaryParameterTypeMismatchException(ResultType.Number | ResultType.ComplexNumber, rightResult, BinaryParameterType.Right);
}

if (rightResult == ResultType.ComplexNumber && (leftResult == ResultType.ComplexNumber || leftResult == ResultType.Number))
return ResultType.ComplexNumber;
if (rightResult == ResultType.ComplexNumber)
{
if (leftResult == ResultType.Number)
return ResultType.ComplexNumber;

throw new BinaryParameterTypeMismatchException(ResultType.Number | ResultType.ComplexNumber, rightResult, BinaryParameterType.Left);
}

if (leftResult == ResultType.Matrix && (rightResult == ResultType.Number || rightResult == ResultType.Matrix || rightResult == ResultType.Vector))
return ResultType.Matrix;

if (rightResult == ResultType.Matrix && (leftResult == ResultType.Number || leftResult == ResultType.Matrix || leftResult == ResultType.Vector))
return ResultType.Matrix;

if (leftResult == ResultType.Vector || (rightResult == ResultType.Number || rightResult == ResultType.Matrix || rightResult == ResultType.Vector))
if (leftResult == ResultType.Vector && (rightResult == ResultType.Number || rightResult == ResultType.Matrix || rightResult == ResultType.Vector))
return ResultType.Vector;

if (leftResult == ResultType.Vector || (leftResult == ResultType.Number || leftResult == ResultType.Matrix || leftResult == ResultType.Vector))
if (rightResult == ResultType.Vector && (leftResult == ResultType.Number || leftResult == ResultType.Matrix || leftResult == ResultType.Vector))
return ResultType.Vector;

if (leftResult == ResultType.Number)
{
if (rightResult == ResultType.Number)
return ResultType.Number;

throw new BinaryParameterTypeMismatchException(ResultType.Number, rightResult, BinaryParameterType.Right);
}

if (rightResult == ResultType.Number)
{
throw new BinaryParameterTypeMismatchException(ResultType.Number, leftResult, BinaryParameterType.Left);
}

// TODO: !!!
throw new ParameterTypeMismatchException();
}
Expand Down
48 changes: 48 additions & 0 deletions xFunc.Tests/Analyzers/TypeAnalyzerTests/StandardTests.cs
Expand Up @@ -748,6 +748,30 @@ public void TestMulNumberVarTest()
Test(mul, ResultType.Undefined);
}

[Fact]
public void TestMulNumberBoolTest()
{
var mul = new Mul(new Number(1), new Bool(true));

TestBinaryException(mul);
}

[Fact]
public void TestMulBoolNumberTest()
{
var mul = new Mul(new Bool(true), new Number(1));

TestBinaryException(mul);
}

[Fact]
public void TestMulVarNumberTest()
{
var mul = new Mul(new Variable("x"), new Number(1));

Test(mul, ResultType.Undefined);
}

[Fact]
public void TestMulTwoMatrixTest()
{
Expand Down Expand Up @@ -798,6 +822,30 @@ public void TestMulComplexNumberNumberTest()
Test(exp, ResultType.ComplexNumber);
}

[Fact]
public void TestMulComplexNumberBoolTest()
{
var exp = new Mul(new ComplexNumber(2, 5), new Bool(true));

TestBinaryException(exp);
}

[Fact]
public void TestMulNumberComplexNumberTest()
{
var exp = new Mul(new Number(2), new ComplexNumber(3, 2));

Test(exp, ResultType.ComplexNumber);
}

[Fact]
public void TestMulBoolComplexNumberTest()
{
var exp = new Mul(new Bool(true), new ComplexNumber(2, 5));

TestBinaryException(exp);
}

[Fact]
public void TestMulException()
{
Expand Down

0 comments on commit 35961b7

Please sign in to comment.