This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using HtnCalc.Core.ExpressionTree; | ||
using Xunit; | ||
|
||
namespace HtnCalc.Core.UnitTests | ||
{ | ||
public class AbsFunctionExpressionTests | ||
{ | ||
[Theory] | ||
[InlineData(3, 3)] | ||
[InlineData(-1.1756, 1.1756)] | ||
public void Calculate(decimal arg, decimal expected) | ||
{ | ||
var expression = new AbsFunctionExpression(new NumberExpression(arg)); | ||
var result = expression.Calculate(); | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData(3, 5, 8)] | ||
[InlineData(1.1756, 138.066, 139.2416)] | ||
public void Calculate_Compound(decimal left, decimal right, decimal expected) | ||
{ | ||
var expression = new AbsFunctionExpression(new AdditionExpression(new NumberExpression(left), new NumberExpression(right))); | ||
var result = expression.Calculate(); | ||
Assert.Equal(expected, result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using HtnCalc.Core.Parsing; | ||
using HtnCalc.Core.Permutation; | ||
using Xunit; | ||
using static Xunit.Assert; | ||
|
||
namespace HtnCalc.Core.UnitTests | ||
{ | ||
public class AddSubTermPermuterTests | ||
{ | ||
[Fact] | ||
public void Permute() | ||
{ | ||
var permuter = new AddSubTermPermuter(); | ||
var list = new LinkedList<ITerm>(new ITerm[] | ||
{ | ||
new NumberToken('3', 1), | ||
new ArithmeticOperatorToken(ArithmeticOperationType.Addition, 3), | ||
new NumberToken('5', 5), | ||
new ArithmeticOperatorToken(ArithmeticOperationType.Subtraction, 6), | ||
new NumberToken('8', 7), | ||
}); | ||
|
||
var result = permuter.Permute(list); | ||
|
||
IsType<CompoundTerm>(result); | ||
Equal(3, result.Terms.Count); | ||
IsType<NumberToken>(result.Terms.First?.Value); | ||
IsType<ArithmeticOperatorToken>(result.Terms.First?.Next?.Value); | ||
IsType<CompoundTerm>(result.Terms.First?.Next?.Next?.Value); | ||
var compoundTerm = (CompoundTerm) result.Terms.First?.Next?.Next?.Value; | ||
Equal(3, result.Terms.Count); | ||
IsType<NumberToken>(compoundTerm.Terms.First?.Value); | ||
IsType<ArithmeticOperatorToken>(compoundTerm.Terms.First?.Next?.Value); | ||
IsType<NumberToken>(compoundTerm.Terms.First?.Next?.Next?.Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using HtnCalc.Core.ExpressionTree; | ||
using HtnCalc.Core.Parsing; | ||
using HtnCalc.Core.Permutation; | ||
using Xunit; | ||
using static Xunit.Assert; | ||
|
||
namespace HtnCalc.Core.UnitTests | ||
{ | ||
public class ExpressionTreeBuilderTests | ||
{ | ||
[Fact] | ||
public void BuildExpressionTree_SimpleArithmetic() | ||
{ | ||
var builder = new ExpressionTreeBuilder(); | ||
var term = new CompoundTerm(new LinkedList<ITerm>(new ITerm[] | ||
{ | ||
new NumberToken('3', 1), | ||
new ArithmeticOperatorToken(ArithmeticOperationType.Addition, 2), | ||
new NumberToken('5', 3) | ||
})); | ||
|
||
var result = builder.BuildExpressionTree(term); | ||
|
||
IsType<AdditionExpression>(result); | ||
var additionExpression = (AdditionExpression) result; | ||
IsType<NumberExpression>(additionExpression.Left); | ||
IsType<NumberExpression>(additionExpression.Right); | ||
} | ||
|
||
[Fact] | ||
public void BuildExpressionTree_SimpleNumber() | ||
{ | ||
var builder = new ExpressionTreeBuilder(); | ||
var term = new NumberToken('3', 1); | ||
|
||
var result = builder.BuildExpressionTree(term); | ||
|
||
IsType<NumberExpression>(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
using HtnCalc.Core.Parsing; | ||
using HtnCalc.Core.Permutation; | ||
using Xunit; | ||
using static Xunit.Assert; | ||
|
||
namespace HtnCalc.Core.UnitTests | ||
{ | ||
public class FunctionTermPermuterTests | ||
{ | ||
[Fact] | ||
public void Permute() | ||
{ | ||
var permuter = new FunctionTermPermuter(); | ||
var list = new LinkedList<ITerm>(new ITerm[] | ||
{ | ||
new NumberToken('2', 1), | ||
new ArithmeticOperatorToken(ArithmeticOperationType.Addition, 2), | ||
new AbsFunctionToken(4), | ||
new OpenBracketToken(8), | ||
new NumberToken('8', 9), | ||
new CloseBracketToken(12), | ||
}); | ||
|
||
var result = permuter.Permute(list); | ||
|
||
IsType<CompoundTerm>(result); | ||
Equal(3, result.Terms.Count); | ||
IsType<NumberToken>(result.Terms.First?.Value); | ||
IsType<ArithmeticOperatorToken>(result.Terms.First?.Next?.Value); | ||
IsType<CompoundTerm>(result.Terms.First?.Next?.Next?.Value); | ||
var compoundTerm = (CompoundTerm) result.Terms.First?.Next?.Next?.Value; | ||
Equal(4, compoundTerm.Terms.Count); | ||
IsType<AbsFunctionToken>(compoundTerm.Terms.First?.Value); | ||
IsType<OpenBracketToken>(compoundTerm.Terms.First?.Next?.Value); | ||
IsType<NumberToken>(compoundTerm.Terms.First?.Next?.Next?.Value); | ||
IsType<CloseBracketToken>(compoundTerm.Terms.First?.Next?.Next?.Next?.Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using HtnCalc.Core.Parsing; | ||
using HtnCalc.Core.Permutation; | ||
using Xunit; | ||
using static Xunit.Assert; | ||
|
||
namespace HtnCalc.Core.UnitTests | ||
{ | ||
public class MulDivTermPermuterTests | ||
{ | ||
[Fact] | ||
public void Permute() | ||
{ | ||
var permuter = new MulDivTermPermuter(); | ||
var list = new LinkedList<ITerm>(new ITerm[] | ||
{ | ||
new NumberToken('3', 1), | ||
new ArithmeticOperatorToken(ArithmeticOperationType.Multiplication, 3), | ||
new NumberToken('5', 5), | ||
new ArithmeticOperatorToken(ArithmeticOperationType.Multiplication, 6), | ||
new NumberToken('8', 7), | ||
}); | ||
|
||
var result = permuter.Permute(list); | ||
|
||
IsType<CompoundTerm>(result); | ||
Equal(3, result.Terms.Count); | ||
IsType<CompoundTerm>(result.Terms.First?.Value); | ||
IsType<ArithmeticOperatorToken>(result.Terms.First?.Next?.Value); | ||
IsType<NumberToken>(result.Terms.First?.Next?.Next?.Value); | ||
var compoundTerm = (CompoundTerm) result.Terms.First?.Value; | ||
Equal(3, result.Terms.Count); | ||
IsType<NumberToken>(compoundTerm.Terms.First?.Value); | ||
IsType<ArithmeticOperatorToken>(compoundTerm.Terms.First?.Next?.Value); | ||
IsType<NumberToken>(compoundTerm.Terms.First?.Next?.Next?.Value); | ||
} | ||
} | ||
} |