3.1P - Clock Class
3.1P - Clock Class
1P - Clock Class
Program source code:
Clock.cs
public class Clock
{
Counter _seccond = new Counter("Seccond");
Counter _minute = new Counter("Minute");
Counter _hour = new Counter("Hour");
}
Program.cs
public class MainClass
{
class Program
{
static void Main(string[] args)
{
Clock clock = new Clock();
int i;
}
Test source code:
TestClock.cs
namespace TestClock
{
public class Tests
{
private Clock _clock;
[SetUp]
public void Setup()
{
_clock = new Clock();
[Test]
public void TestReset()
{
int i;
for (i = 0; i < 86400; i++)
{
_clock.Tick();
}
_clock.Reset();
ClassicAssert.AreEqual("00:00:00", _clock.CurrentTime());
[TestCase(0, "00:00:00")]
[TestCase(60, "00:01:00")]
[TestCase(120, "00:02:00")]
[TestCase(86340, "23:59:00")]
}
TestCounter.cs
using CounterTask;
using NUnit.Framework.Legacy;
namespace TestClock
{
internal class TestCounter
{
Counter _countertest;
[SetUp]
public void Setup()
{
_countertest = new Counter("Test");
}
[Test]
public void test_start9()
{
ClassicAssert.AreEqual(0, _countertest.Tick);
}
[Test]
public void test_name()
{
ClassicAssert.AreEqual("Test", _countertest.Name);
}
[Test]
public void test_count_reset()
{
_countertest.Increment();
_countertest.Reset();
ClassicAssert.AreEqual(0, _countertest.Tick);
}
[TestCase(60, 60)]
[TestCase(100, 100)]
public void test_increment(int tick, int result)
{
int i;
for (i = 0; i < tick; i++)
{
_countertest.Increment();
}
ClassicAssert.AreEqual(result, _countertest.Tick);
}
}
}
Screenshot of unit test results