Skip to content

Commit

Permalink
add: documentation for public classes and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantin.ovsyannikov committed Nov 26, 2023
1 parent a569998 commit b2aaa9c
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 7 deletions.
51 changes: 47 additions & 4 deletions HW05UNIT/UNIT/Assert.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
namespace Unit;

/// <summary>
/// Class for asserting statements
/// </summary>
public static class Assert
{
public static void IsTrue(bool condition)
/// <summary>
/// Check if statement is true
/// </summary>
/// <param name="statement">Statement to check</param>
/// <exception cref="Exception">Thrown if statement is false</exception>
public static void IsTrue(bool statement)
{
if (!condition)
if (!statement)
{
throw new Exception("ACHTUNG! Assert.IsTrue failed!");
}
}

public static void IsFalse(bool condition)
/// <summary>
/// Check if statement is false
/// </summary>
/// <param name="statement">Statement to check</param>
/// <exception cref="Exception">Thrown if statement is true</exception>
public static void IsFalse(bool statement)
{
if (condition)
if (statement)
{
throw new Exception("ACHTUNG! Assert.IsFalse failed");
}
}

/// <summary>
/// Check if two objects are equal
/// </summary>
/// <param name="a">First object</param>
/// <param name="b">Second object</param>
/// <exception cref="Exception">Thrown if objects are not equal</exception>
public static void AreEqual(object a, object b)
{
if (!a.Equals(b))
Expand All @@ -26,6 +45,12 @@ public static void AreEqual(object a, object b)
}
}

/// <summary>
/// Check if two objects are not equal
/// </summary>
/// <param name="a">First object</param>
/// <param name="b">Second object</param>
/// <exception cref="Exception">Thrown if objects are equal</exception>
public static void AreNotEqual(object a, object b)
{
if (a.Equals(b))
Expand All @@ -34,6 +59,11 @@ public static void AreNotEqual(object a, object b)
}
}

/// <summary>
/// Check if object is null
/// </summary>
/// <param name="a">Object</param>
/// <exception cref="Exception">Thrown if object is not null</exception>
public static void IsNull(object a)
{
if (a != null)
Expand All @@ -42,6 +72,11 @@ public static void IsNull(object a)
}
}

/// <summary>
/// Check if object is not null
/// </summary>
/// <param name="a">Object</param>
/// <exception cref="Exception">Thrown if object is null</exception>
public static void IsNotNull(object a)
{
if (a == null)
Expand All @@ -50,6 +85,11 @@ public static void IsNotNull(object a)
}
}

/// <summary>
/// Fails always
/// </summary>
/// <param name="message">Custom message to add in exception message</param>
/// <exception cref="Exception">Thrown always. Contains custom message</exception>
public static void Fail(string message)
{
if (message.Count() != 0)
Expand All @@ -59,6 +99,9 @@ public static void Fail(string message)
throw new Exception($"ACHTUNG! Failed{message}");
}

/// <summary>
/// Fails always
/// </summary>
public static void Fail()
{
Fail("");
Expand Down
31 changes: 31 additions & 0 deletions HW05UNIT/UNIT/Attributes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace Unit;


/// <summary>
/// Marks test methods
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class Test : Attribute
{
Expand All @@ -8,38 +12,65 @@ public class Test : Attribute

public Test() {}

/// <summary>
///
/// </summary>
/// <param name="ignore">Skips marked test method if not "NORMAL" value</param>
public Test(string ignore)
{
Ignore = ignore;
}

/// <summary>
///
/// </summary>
/// <param name="expected">Expects exceptions, with method noted in expected array</param>
public Test(string[] expected)
{
Expected = expected;
}

/// <summary>
///
/// </summary>
/// <param name="expected">Expects exceptions, with method noted in expected array</param>
/// <param name="ignore">Skips marked test method if not "NORMAL" value</param>
public Test(string[] expected, string ignore)
{
Expected = expected;
Ignore = ignore;
}
}


/// <summary>
/// Marks method running before all test methods
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class BeforeClass : Attribute
{
}


/// <summary>
/// Marks method running after all test methods
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class AfterClass : Attribute
{
}

/// <summary>
/// Marks method running before each test method
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class Before : Attribute
{
}

/// <summary>
/// Marks method running after each test method
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class After : Attribute
{
Expand Down
4 changes: 4 additions & 0 deletions HW05UNIT/UNIT/InfoWriter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace Unit;


/// <summary>
/// Writes stats and messages in pretty form using templates
/// </summary>
public static class InfoWriter
{
public static void WriteStatsSpecialMethods(Type t, Action? beforeClass, Action? afterClass,
Expand Down
9 changes: 8 additions & 1 deletion HW05UNIT/UNIT/TestLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Unit;

public class TestLauncher
/// <summary>
/// Runs tests for every assembly in chosen path
/// </summary>
public static class TestLauncher
{
private static List<Assembly> assemblies = new();
private static IEnumerable<string> GetAssemblyPaths(string path)
Expand All @@ -25,6 +28,10 @@ private static bool IsAssemblyLoaded(string path)
return false;
}

/// <summary>
/// Runs tests for every assembly in chosen path
/// </summary>
/// <param name="path">Path to folder, holding the assemblies</param>
public static void RunTests(string path)
{
var paths = GetAssemblyPaths(path);
Expand Down
15 changes: 13 additions & 2 deletions HW05UNIT/UNIT/Tester.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using System.Diagnostics;

namespace Unit;

/// <summary>
/// Runs test for given assembly
/// </summary>
public class Tester
{
private Assembly _asm;

/// <summary>
/// Creates tester object using path
/// </summary>
/// <param name="asm">Assembly path</param>
public Tester(Assembly asm)
{
_asm = asm;
Expand Down Expand Up @@ -150,7 +158,6 @@ private void RunSpecialMethods(Action? beforeClass, Action? afterClass,
failedCount++;
}
}
// Console.WriteLine(stopwatch.ElapsedMilliseconds);
elapsedTime.Add(stopwatch.ElapsedMilliseconds);
stopwatch.Reset();

Expand All @@ -166,8 +173,12 @@ private void RunSpecialMethods(Action? beforeClass, Action? afterClass,
}

InfoWriter.WriteTestResults(elapsedTime, testMethods, failedCount, skippedCount);
}
}


/// <summary>
/// Runst test methods in selected assembly
/// </summary>
public void RunTests()
{
foreach (var t in _asm.ExportedTypes)
Expand Down

0 comments on commit b2aaa9c

Please sign in to comment.