public void EqualsReturnsFalseForDifferentTypeArgument() { // arrange var originalVector = SparseVectorHelper.GenerateRandomVector(1000, 0.7, () => SparseVectorHelper.RandomInInterval(-100, 100, 2)); var sv = new SparseVector <double>(originalVector); // act var falseResult1 = sv.Equals(string.Empty); // assert Assert.IsFalse(falseResult1); }
public void EnumeratorReturnsOnlyNonZeroValuePairsOrderedByIndexAscending() { // arrange var originalVector = SparseVectorHelper.GenerateRandomVector(1000, 0.7, () => SparseVectorHelper.RandomInInterval(-100, 100, 2)); var sv = new SparseVector <double>(originalVector); var nonZeroValuesPairs = originalVector.Where(pair => pair.Value != 0.0).OrderBy(pair => pair.Key).ToArray(); // act // assert Assert.IsTrue(sv.SequenceEqual(nonZeroValuesPairs)); }
public void IndexedPropertyGetAccessorReturnsWhatWasSavedThroughConstructor() { // arrange var originalVector = SparseVectorHelper.GenerateRandomVector(1000, 0.7, () => SparseVectorHelper.RandomInInterval(-100, 100, 2)); // act var sv = new SparseVector <double>(originalVector); // assert foreach (var element in originalVector) { Assert.AreEqual(element.Value, sv[element.Key]); } }
public void GetHashCodeReturnsSameHashCodeForEqualSparseVectors() { // arrange var originalVector = SparseVectorHelper.GenerateRandomVector(1000, 0.7, () => SparseVectorHelper.RandomInInterval(-100, 100, 2)); var originalVectorCopy = originalVector.ToArray(); var sv1 = new SparseVector <double>(originalVector); var sv2 = new SparseVector <double>(originalVectorCopy); // act var hc1 = sv1.GetHashCode(); var hc2 = sv2.GetHashCode(); // assert Assert.AreEqual(hc1, hc2); }
public void EqualsReturnsTrueForSameReferenceObjects() { // arrange var originalVector = SparseVectorHelper.GenerateRandomVector(1000, 0.7, () => SparseVectorHelper.RandomInInterval(-100, 100, 2)); var sv1 = new SparseVector <double>(originalVector); SparseVector <double> sv2 = sv1; // act var trueResult1 = sv1.Equals(sv2); var trueResult2 = sv1.Equals((object)sv2); // assert Assert.IsTrue(trueResult1); Assert.IsTrue(trueResult2); }
public void EqualsReturnsFalseForNullArgument() { // arrange var originalVector = SparseVectorHelper.GenerateRandomVector(1000, 0.7, () => SparseVectorHelper.RandomInInterval(-100, 100, 2)); var sv1 = new SparseVector <double>(originalVector); SparseVector <double> sv2 = null; // act var falseResult1 = sv1.Equals(sv2); var falseResult2 = sv1.Equals((object)sv2); // assert Assert.IsFalse(falseResult1); Assert.IsFalse(falseResult2); }
public void EqualOperatorReturnsTrueForEqualSparseVectors() { // arrange var originalVector = SparseVectorHelper.GenerateRandomVector(1000, 0.7, () => SparseVectorHelper.RandomInInterval(-100, 100, 2)); var originalVectorCopy = originalVector.ToArray(); var sv1 = new SparseVector <double>(originalVector); var sv2 = new SparseVector <double>(originalVectorCopy); // act var trueResult = sv1 == sv2; var falseResult = sv1 != sv2; // assert Assert.IsTrue(trueResult); Assert.IsFalse(falseResult); }
public void NonZeroValuesCountReturnsOnlyNonZeroElementsCount() { // arrange var originalVector = SparseVectorHelper.GenerateRandomVector(1000, 0.7, () => SparseVectorHelper.RandomInInterval(-100, 100, 2)); var nonZeroElementsCount = originalVector.Count(arg => arg.Value != 0.0); var sv = new SparseVector <double>(); // act foreach (var element in originalVector) { sv[element.Key] = element.Value; } // assert Assert.AreEqual(nonZeroElementsCount, sv.NonZeroValuesCount); }