Skip to content

Commit

Permalink
Refactor and cover edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
maacpiash committed Jul 26, 2020
1 parent 53de4fd commit 5da5220
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/Models/Inference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,26 @@ public static (double, double, double)[,] ComparisonMatrix(int[] values)
public static (double, double, double) FuzzyMultiply(this (double, double, double) a, (double, double, double) b)
{
double[] Items = { a.Item1 * b.Item1, a.Item1 * b.Item3, a.Item3 * b.Item1, a.Item3 * b.Item3 };
// a1b1 a1b3 a3b1 a3b3
double Left = Items[0], Middle = a.Item2 * b.Item2, Right = Items[0];

for (int i = 1; i < 4; i++)
{
if (Items[i] < Left)
Left = Items[i];
if (Items[i] > Right)
Right = Items[i];
}

// a1b1 a1b3 a3b1 a3b3
var (Left, Right) = GetMinMax(Items);
double Middle = a.Item2 * b.Item2;
return (Left, Middle, Right);
}

public static (double, double, double) Inverse(this (double, double, double) a)
=> (1.0 / a.Item3, 1.0 / a.Item2, 1.0 / a.Item1);

public static (double, double) GetMinMax(double[] values)
{
double min = values[0], max = values[0];
for (int i = 1; i < values.Length; i++)
{
if (values[i] < min)
min = values[i];
if (values[i] > max)
max = values[i];
}
return (min, max);
}
}
}
10 changes: 10 additions & 0 deletions tests/ModelTests/Inference.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ namespace KonSchool.Tests.ModelTests
{
public class InferenceTests
{
[Theory]
[InlineData(1.0, 2.0, 3.0, 4.0, 5.0)]
[InlineData(5.0, 4.0, 3.0, 2.0, 1.0)]
public void Can_GetMinMax(params double[] values)
{
var (min, max) = GetMinMax(values);
Assert.Equal(1.0, min);
Assert.Equal(5.0, max);
}

[Fact]
public void Can_FuzzyMultiply()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/ModelTests/School.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ public class SchoolTests
[Fact]
public void Can_GetSetValues()
{
School school = new School(121212)
School school = new School(108277)
{
Id = "108277",
Name = "Ideal School & College",
OLD = 0.7,
Division = "Dhaka",
Expand Down

0 comments on commit 5da5220

Please sign in to comment.