@Test public void shouldReturnSumOfOneVectorIfOtherIsFullOfOnes() { Vector v1 = new Vector(2, 2, 2, 2); Vector v2 = new Vector(1, 1, 1, 1); int result = vectorScalarProduct.calculateScalarProduct(v1, v2); assertEquals(8, result); }
public int calculateScalarProduct(Vector v1, Vector v2) { validateInput(v1, v2); int v1Size = v1.size(); int v2Size = v2.size(); if (v1Size != v2Size) { throw new IllegalArgumentException("Vectors should be contains the same number of elements."); } int result = 0; for (int i = 0; i < v1Size; i++) { result += v1.getAt(i) * v2.getAt(i); } return result; }
VectorScalarProduct { public int calculateScalarProduct(Vector v1, Vector v2) { validateInput(v1, v2); int v1Size = v1.size(); int v2Size = v2.size(); if (v1Size != v2Size) { throw new IllegalArgumentException("Vectors should be contains the same number of elements."); } int result = 0; for (int i = 0; i < v1Size; i++) { result += v1.getAt(i) * v2.getAt(i); } return result; } }
VectorScalarProduct { public int calculateScalarProduct(Vector v1, Vector v2) { validateInput(v1, v2); int v1Size = v1.size(); int v2Size = v2.size(); if (v1Size != v2Size) { throw new IllegalArgumentException("Vectors should be contains the same number of elements."); } int result = 0; for (int i = 0; i < v1Size; i++) { result += v1.getAt(i) * v2.getAt(i); } return result; }  }
VectorScalarProduct { public int calculateScalarProduct(Vector v1, Vector v2) { validateInput(v1, v2); int v1Size = v1.size(); int v2Size = v2.size(); if (v1Size != v2Size) { throw new IllegalArgumentException("Vectors should be contains the same number of elements."); } int result = 0; for (int i = 0; i < v1Size; i++) { result += v1.getAt(i) * v2.getAt(i); } return result; }  int calculateScalarProduct(Vector v1, Vector v2); }
VectorScalarProduct { public int calculateScalarProduct(Vector v1, Vector v2) { validateInput(v1, v2); int v1Size = v1.size(); int v2Size = v2.size(); if (v1Size != v2Size) { throw new IllegalArgumentException("Vectors should be contains the same number of elements."); } int result = 0; for (int i = 0; i < v1Size; i++) { result += v1.getAt(i) * v2.getAt(i); } return result; }  int calculateScalarProduct(Vector v1, Vector v2);  }