-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Start of simple rewrite with fluent api in mind
- Loading branch information
Showing
17 changed files
with
616 additions
and
862 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using FakeItEasy; | ||
using Scientist.Test.Helpers; | ||
using System; | ||
|
||
namespace Scientist.Test.Comparison | ||
{ | ||
public class ComparisonTests | ||
{ | ||
[Test] | ||
public void OverrideComparison() | ||
{ | ||
var testMethods = A.Fake<ITestClass<ComplexResult>>(); | ||
|
||
var complexResult = A.Fake<ComplexResult>(); | ||
complexResult.Name = "Tester"; | ||
complexResult.Count = 10; | ||
A.CallTo(() => testMethods.Control()).Returns(complexResult); | ||
A.CallTo(() => testMethods.Candidate()).Returns(complexResult); | ||
|
||
var result = new Experiment<ComplexResult>( | ||
name: nameof(OverrideComparison), | ||
control: testMethods.Control, | ||
throwOnMismatch: true | ||
) | ||
.AddCandidate(testMethods.Candidate) | ||
.Compare((a, b) => a.Count == b.Count && a.Name == b.Name) | ||
.Run(); | ||
|
||
A.CallTo(() => testMethods.Control()).MustHaveHappened(); | ||
A.CallTo(() => testMethods.Candidate()).MustHaveHappened(); | ||
result.Should().Be(complexResult); | ||
} | ||
|
||
[Test] | ||
public void ThrowMismatchOnOverrideComparison() | ||
{ | ||
var testMethods = A.Fake<ITestClass<ComplexResult>>(); | ||
|
||
var complexResult = A.Fake<ComplexResult>(); | ||
complexResult.Name = "Tester"; | ||
complexResult.Count = 10; | ||
A.CallTo(() => testMethods.Control()).Returns(complexResult); | ||
A.CallTo(() => testMethods.Candidate()).Returns(complexResult); | ||
|
||
Action act = () => new Experiment<ComplexResult>( | ||
name: nameof(ThrowMismatchOnOverrideComparison), | ||
control: testMethods.Control, | ||
throwOnMismatch: true | ||
) | ||
.AddCandidate(testMethods.Candidate) | ||
.Compare((a, b) => a.Count == 2 && a.Name == b.Name) | ||
.Run(); | ||
|
||
act.Should().Throw<MismatchException<ComplexResult>>() | ||
.WithMessage($"Experiment '{nameof(ThrowMismatchOnOverrideComparison)}' observations mismatched"); | ||
A.CallTo(() => testMethods.Control()).MustHaveHappened(); | ||
A.CallTo(() => testMethods.Candidate()).MustHaveHappened(); | ||
} | ||
} | ||
} |
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,111 @@ | ||
using FakeItEasy; | ||
using Scientist.Test.Helpers; | ||
using System; | ||
|
||
namespace Scientist.Test.Experiment | ||
{ | ||
public class ExperimentTests | ||
{ | ||
[Test] | ||
public void WithoutACandidate() | ||
{ | ||
int actualResult = 42; | ||
|
||
var testMethods = A.Fake<ITestClass<int>>(); | ||
A.CallTo(() => testMethods.Control()).Returns(actualResult); | ||
A.CallTo(() => testMethods.Candidate()).Returns(actualResult); | ||
|
||
var result = new Experiment<int>(name: nameof(WithoutACandidate), control: testMethods.Control, throwOnMismatch: true).Run(); | ||
|
||
A.CallTo(() => testMethods.Control()).MustHaveHappened(); | ||
result.Should().Be(actualResult); | ||
} | ||
|
||
[Test] | ||
public void WithACandidate() | ||
{ | ||
int actualResult = 42; | ||
|
||
var testMethods = A.Fake<ITestClass<int>>(); | ||
A.CallTo(() => testMethods.Control()).Returns(actualResult); | ||
A.CallTo(() => testMethods.Candidate()).Returns(actualResult); | ||
|
||
var result = new Experiment<int>(name: nameof(WithACandidate), control: testMethods.Control, throwOnMismatch: true).AddCandidate(testMethods.Candidate) | ||
.Run(); | ||
|
||
A.CallTo(() => testMethods.Control()).MustHaveHappened(); | ||
A.CallTo(() => testMethods.Candidate()).MustHaveHappened(); | ||
result.Should().Be(actualResult); | ||
} | ||
|
||
[Test] | ||
public void WithMultipleCandidates() | ||
{ | ||
int actualResult = 42; | ||
|
||
var testMethods = A.Fake<ITestClass<int>>(); | ||
var fakeCandidate = A.Fake<Func<int>>(); | ||
A.CallTo(() => testMethods.Control()).Returns(actualResult); | ||
A.CallTo(() => testMethods.Candidate()).Returns(actualResult); | ||
A.CallTo(() => fakeCandidate()).Returns(actualResult); | ||
|
||
var result = new Experiment<int>( | ||
name: nameof(WithMultipleCandidates), | ||
control: testMethods.Control, throwOnMismatch: true) | ||
.AddCandidate(testMethods.Candidate) | ||
.AddCandidate(fakeCandidate) | ||
.Run(); | ||
|
||
A.CallTo(() => testMethods.Control()).MustHaveHappened(); | ||
A.CallTo(() => testMethods.Candidate()).MustHaveHappened(); | ||
A.CallTo(() => fakeCandidate()).MustHaveHappened(); | ||
result.Should().Be(actualResult); | ||
} | ||
|
||
[Test] | ||
public void ThrowOnMismatch() | ||
{ | ||
int actualResult = 42; | ||
|
||
var testMethods = A.Fake<ITestClass<int>>(); | ||
var fakeCandidate = A.Fake<Func<int>>(); | ||
A.CallTo(() => testMethods.Control()).Returns(actualResult); | ||
A.CallTo(() => testMethods.Candidate()).Returns(33); | ||
A.CallTo(() => fakeCandidate()).Returns(21); | ||
|
||
Action act = () => new Experiment<int>( | ||
name: nameof(ThrowOnMismatch), | ||
control: testMethods.Control, throwOnMismatch: true) | ||
.AddCandidate(testMethods.Candidate) | ||
.AddCandidate(testMethods.Candidate) | ||
.Run(); | ||
|
||
act.Should().Throw<MismatchException<int>>() | ||
.WithMessage($"Experiment '{nameof(ThrowOnMismatch)}' observations mismatched"); | ||
A.CallTo(() => testMethods.Control()).MustHaveHappened(); | ||
A.CallTo(() => testMethods.Candidate()).MustHaveHappened(); | ||
} | ||
|
||
|
||
[Test] | ||
public void ThrowOnMismatchTurnedOffDoesntThrow() | ||
{ | ||
int actualResult = 42; | ||
|
||
var testMethods = A.Fake<ITestClass<int>>(); | ||
var fakeCandidate = A.Fake<Func<int>>(); | ||
A.CallTo(() => testMethods.Control()).Returns(actualResult); | ||
A.CallTo(() => testMethods.Candidate()).Returns(33); | ||
|
||
Action act = () => new Experiment<int>( | ||
name: nameof(ThrowOnMismatchTurnedOffDoesntThrow), | ||
control: testMethods.Control) | ||
.AddCandidate(testMethods.Candidate) | ||
.Run(); | ||
|
||
act.Should().NotThrow<MismatchException<int>>(); | ||
A.CallTo(() => testMethods.Control()).MustHaveHappened(); | ||
A.CallTo(() => testMethods.Candidate()).MustHaveHappened(); | ||
} | ||
} | ||
} |
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,2 @@ | ||
global using NUnit.Framework; | ||
global using FluentAssertions; |
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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Scientist.Test.Helpers | ||
{ | ||
public class ComplexResult : IEquatable<ComplexResult> | ||
{ | ||
public int Count { get; set; } | ||
public string Name { get; set; } | ||
|
||
public bool Equals(ComplexResult other) | ||
{ | ||
if (other == null) | ||
return false; | ||
|
||
return Count == other.Count && Name == other.Name; | ||
} | ||
} | ||
} |
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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Scientist.Test.Helpers | ||
{ | ||
public interface ITestClass<T> | ||
{ | ||
T Control(); | ||
T Candidate(); | ||
} | ||
} |
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,14 @@ | ||
namespace Scientist.Test.Publishing | ||
{ | ||
public class PublishingTests | ||
{ | ||
[Test] | ||
public void DefaultPublisher() { } | ||
|
||
[Test] | ||
public void CustomPublisher() { } | ||
|
||
[Test] | ||
public void FireAndForget() { } | ||
} | ||
} |
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,54 @@ | ||
using FakeItEasy; | ||
using Scientist.Test.Helpers; | ||
using System; | ||
|
||
namespace Scientist.Test.RunIf | ||
{ | ||
public class RunIfTests | ||
{ | ||
|
||
[Test] | ||
public void RunIfFalse() | ||
{ | ||
int actualResult = 42; | ||
|
||
var testMethods = A.Fake<ITestClass<int>>(); | ||
var runIf = A.Fake<Func<bool>>(); | ||
A.CallTo(() => testMethods.Control()).Returns(actualResult); | ||
A.CallTo(() => runIf()).Returns(false); | ||
|
||
var result = new Experiment<int>( | ||
name: nameof(RunIfFalse), | ||
control: testMethods.Control) | ||
.AddCandidate(testMethods.Candidate) | ||
.RunIf(runIf); | ||
|
||
A.CallTo(() => testMethods.Control()).MustHaveHappened(); | ||
A.CallTo(() => runIf()).MustHaveHappened(); | ||
A.CallTo(() => testMethods.Candidate()).MustNotHaveHappened(); | ||
result.Should().Be(actualResult); | ||
} | ||
|
||
[Test] | ||
public void RunIfTrue() | ||
{ | ||
int actualResult = 42; | ||
|
||
var testMethods = A.Fake<ITestClass<int>>(); | ||
var runIf = A.Fake<Func<bool>>(); | ||
A.CallTo(() => testMethods.Control()).Returns(actualResult); | ||
A.CallTo(() => runIf()).Returns(true); | ||
|
||
var result = new Experiment<int>( | ||
name: nameof(RunIfTrue), | ||
control: testMethods.Control) | ||
.AddCandidate(testMethods.Candidate) | ||
.RunIf(runIf); | ||
|
||
A.CallTo(() => testMethods.Control()).MustHaveHappened(); | ||
A.CallTo(() => runIf()).MustHaveHappened(); | ||
A.CallTo(() => testMethods.Candidate()).MustHaveHappened(); | ||
result.Should().Be(actualResult); | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.