public void Sub() { SparseVectori sub = v1 - v2; Assert.AreEqual((int)2.0, sub[1]); Assert.AreEqual((int)-2.0, sub[2]); }
public void Add() { SparseVectori add = v1 + v2; Assert.AreEqual((int)2.0, add[1]); Assert.AreEqual((int)2.0, add[2]); Assert.AreEqual(0, add[3]); Assert.AreEqual((int)14.0, add[5]); Assert.AreEqual((int)5.0, add[12]); Assert.AreEqual((int)5.0, add[14]); }
public void ElementConstructionAndAccess() { // We construct giant sparse vector. SparseVectori v = new SparseVectori( new SparseElementi[] { new SparseElementi(1, (int)2.0), new SparseElementi(5, (int)3.0), new SparseElementi(12, (int)4.0), new SparseElementi(115, (int)70.0) }, 150); // Accessor test. Assert.AreEqual(0, v[7]); Assert.AreEqual((int)3.0, v[5]); Assert.AreEqual((int)70.0, v[115]); Assert.AreEqual(0, v[145]); // Setting test. v[15] = (int)6.0; Assert.AreEqual((int)6.0, v[15]); v[5] = (int)3.0; Assert.AreEqual((int)3.0, v[5]); }