// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using NUnit.Framework; [TestFixture] public class MathVectorTest { [SetUp] protected void Init() { } [TearDown] protected void Dispose() { } [Test] public void Add() { int[] v = { -1000000, -1, 0, 1, 1000000 }; MathVector mv = new MathVector(v); MathVector mv2 = mv.Add(777); Assert.AreEqual(mv.Count, mv2.Count, "Add Count"); for(int i = 0; i < mv2.Count; i++) { Assert.AreEqual(mv.V[i] + 777, mv2.V[i], "Add " + i); } } [Test] public void Sub() { int[] v = { -1000000, -1, 0, 1, 1000000 }; MathVector mv = new MathVector(v); MathVector mv2 = mv.Sub(777); Assert.AreEqual(mv.Count, mv2.Count, "Sub Count"); for(int i = 0; i < mv2.Count; i++) { Assert.AreEqual(mv.V[i] - 777, mv2.V[i], "Sub " + i); } } [Test] public void Mul() { int[] v = { -1000000, -1, 0, 1, 1000000 }; MathVector mv = new MathVector(v); MathVector mv2 = mv.Mul(777); Assert.AreEqual(mv.Count, mv2.Count, "Mul Count"); for(int i = 0; i < mv2.Count; i++) { Assert.AreEqual(mv.V[i] * 777, mv2.V[i], "Mul " + i); } } [Test] public void Div() { int[] v = { -1000000, -1, 0, 1, 1000000 }; MathVector mv = new MathVector(v); MathVector mv2 = mv.Div(777); Assert.AreEqual(mv.Count, mv2.Count, "Div Count"); for(int i = 0; i < mv2.Count; i++) { Assert.AreEqual(mv.V[i] / 777, mv2.V[i], "Div " + i); } } [Test] public void Mod() { int[] v = { -1000000, -1, 0, 1, 1000000 }; MathVector mv = new MathVector(v); MathVector mv2 = mv.Mod(777); Assert.AreEqual(mv.Count, mv2.Count, "Mod Count"); for(int i = 0; i < mv2.Count; i++) { Assert.AreEqual(mv.V[i] % 777, mv2.V[i], "Mod " + i); } } }