From 0b4849692ff13eb313d9cbf4e570cb842fde1047 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 8 Sep 2019 02:13:49 +0300 Subject: Added Wave.cs tests (and fixed a Wave.cs problem) --- Oscilloscope/Oscilloscope/Wave.cs | 4 ++-- Oscilloscope/OscilloscopeTests/WaveTests.cs | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Oscilloscope/Oscilloscope/Wave.cs b/Oscilloscope/Oscilloscope/Wave.cs index 6ca5b6f..1f5e915 100644 --- a/Oscilloscope/Oscilloscope/Wave.cs +++ b/Oscilloscope/Oscilloscope/Wave.cs @@ -41,8 +41,8 @@ namespace Oscilloscope public string Name { get { return this.name; } set { - if (name == "") { - throw new ArgumentException("Name cannot be emty string!"); + if (value == "") { + throw new ArgumentException("Name cannot be empty string!"); } name = value; diff --git a/Oscilloscope/OscilloscopeTests/WaveTests.cs b/Oscilloscope/OscilloscopeTests/WaveTests.cs index aae4f17..f75634d 100644 --- a/Oscilloscope/OscilloscopeTests/WaveTests.cs +++ b/Oscilloscope/OscilloscopeTests/WaveTests.cs @@ -7,6 +7,28 @@ using System.Collections.Generic; namespace OscilloscopeTests { [TestFixture] public class WaveTests { - + + [Test] + public static void InitialisationOverloadsNameCreaton() { + Wave wave1 = new Wave(); + Wave wave2 = new Wave("My wave"); + + Assert.AreEqual("Wave1", wave1.Name, "Automatic wave name isn't working properly."); + Assert.AreEqual("My wave", wave2.Name, "Custom wave name from overload doesn't work correctly."); + + var testException = Assert.Throws(() => new Wave("")); + Assert.AreEqual("Name cannot be empty string!", testException.Message, "There is no eception if you input an empty string as a name"); + } + + [Test] + public static void InitialisationWithAListOfValues() { + var testValues = new List() { int.MinValue, int.MinValue + 1, 0, int.MaxValue - 1, int.MaxValue }; + Wave testWave = new Wave(new List() { int.MinValue, int.MinValue + 1, 0, int.MaxValue - 1, int.MaxValue}); + + for (int i = 0; i < 5; i++) { + Assert.AreEqual(testValues[i], testWave.GetValue(), $"Wave doesn't return right value (failed on value No {i})"); + } + Assert.AreEqual(testValues[0], testWave.GetValue(), "Wave doesn't reset return index variable correctly."); + } } } -- cgit v1.2.3