Last active
December 17, 2015 10:09
-
-
Save Karql/5592703 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Reflection; | |
namespace MiniTestFramework | |
{ | |
public interface AssertionInteface | |
{ | |
string Message { get; } | |
bool check(int sample); | |
} | |
public class EqAssertion : AssertionInteface | |
{ | |
public string Message { get { return "equal"; } } | |
protected int value; | |
public EqAssertion(int v) | |
{ | |
this.value = v; | |
} | |
bool AssertionInteface.check(int sample) | |
{ | |
return ( sample == this.value ); | |
} | |
} | |
public class BeetwenAssertion : AssertionInteface | |
{ | |
public string Message { get { return "beetwen"; } } | |
protected int value1; | |
protected int value2; | |
public BeetwenAssertion(int v1, int v2) | |
{ | |
this.value1 = v1; | |
this.value2 = v2; | |
} | |
bool AssertionInteface.check(int sample) | |
{ | |
return ( sample > this.value1 && sample < this.value2 ); | |
} | |
} | |
public class Expectation | |
{ | |
protected int value; | |
public Expectation(int v) | |
{ | |
this.value = v; | |
} | |
public void to(AssertionInteface assertion) | |
{ | |
// if not ok | |
if (!assertion.check(this.value)) | |
{ | |
throw new Exception("not " + assertion.Message); | |
} | |
} | |
public void not_to(AssertionInteface assertion) | |
{ | |
// because is not_to so when is ok is not:) | |
if (assertion.check(this.value)) | |
{ | |
throw new Exception(assertion.Message); | |
} | |
} | |
} | |
public abstract class TestBase | |
{ | |
public Expectation except(int val) | |
{ | |
return new Expectation(val); | |
} | |
public AssertionInteface eq(int v) | |
{ | |
return new EqAssertion(v); | |
} | |
public AssertionInteface be_beetwen(int v1, int v2) | |
{ | |
return new BeetwenAssertion(v1, v2); | |
} | |
public void RunTests() | |
{ | |
foreach (var test in this.GetType().GetMethods()) | |
{ | |
if (test.Name.StartsWith("test_")) | |
{ | |
try | |
{ | |
test.Invoke(this, null); | |
} | |
catch (TargetInvocationException e) | |
{ | |
Console.WriteLine(e.InnerException.Message); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment