using Microsoft.VisualStudio.TestTools.UnitTesting; using T5; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace T5.Tests { [TestClass()] public class ArrayCalcsTests { [TestMethod()] public void SumEmptyTest() { // arrange double[] array = { }; // act double actual; try { actual = ArrayCalcs.Sum(array); } catch (ArgumentOutOfRangeException e) { StringAssert.Contains(e.Message, ArrayCalcs.ArrayIsEmptyMessage); return; } Assert.Fail("No exception was thrown."); } [TestMethod()] public void SumTest() { // arrange double[] array = { -2,0, -1.0, 0.0, 1.0, 2.0 }; double expected = 0; // act double actual = ArrayCalcs.Sum(array); // assert Assert.AreEqual(expected, actual); } [TestMethod()] public void AverageEmptyTest() { // arrange double[] array = { }; // act double actual; try { actual = ArrayCalcs.Average(array); } catch (ArgumentOutOfRangeException e) { StringAssert.Contains(e.Message, ArrayCalcs.ArrayIsEmptyMessage); return; } Assert.Fail("No exception was thrown."); } [TestMethod()] public void AverageTest() { // arrange double[] array = { -2, 0, -1.0, 0.0, 1.0, 2.0 }; double expected = 0; // act double actual = ArrayCalcs.Average(array); // assert Assert.AreEqual(expected, actual); } [TestMethod()] public void MinEmptyTest() { // arrange double[] array = { }; // act double actual; try { actual = ArrayCalcs.Min(array); } catch (ArgumentOutOfRangeException e) { StringAssert.Contains(e.Message, ArrayCalcs.ArrayIsEmptyMessage); return; } Assert.Fail("No exception was thrown."); } [TestMethod()] public void MinTest() { // arrange double[] array = { -2, 0, -1.0, 0.0, 1.0, 2.0 }; double expected = -2.0; // act double actual = ArrayCalcs.Min(array); // assert Assert.AreEqual(expected, actual); } [TestMethod()] public void MaxEmptyTest() { // arrange double[] array = { }; // act double actual; try { actual = ArrayCalcs.Max(array); } catch (ArgumentOutOfRangeException e) { StringAssert.Contains(e.Message, ArrayCalcs.ArrayIsEmptyMessage); return; } Assert.Fail("No exception was thrown."); } [TestMethod()] public void MaxTest() { // arrange double[] array = { -2, 0, -1.0, 0.0, 1.0, 2.0 }; double expected = 2.0; // act double actual = ArrayCalcs.Max(array); // assert Assert.AreEqual(expected, actual); } } }