package linear.doubles;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

import org.junit.Before;
import org.junit.Test;

public final class VectorSpec {

  private Vector vec1;
  private Vector vec2;
  private Vector vec3;

  @Before
  public void beforeMethod() {
    vec1 = new Vector(3.0, 4.0, 7.5);
    vec2 = new Vector(4.5, 5.0, 2.0, 5.5);
    vec3 = new Vector(6.0, 2.5, 10.0);
  }
  
  @Test
  public void whenOuterProductComputedResultingMatrixCorrect() {
    Matrix matrix = vec1.outerProduct(vec2);
    double[] expected = new double[] { 13.5, 15.0, 6.0, 16.5, 18.0, 20.0,
        8.0, 22.0, 33.75, 37.5, 15.0, 41.25};
    assertThat(matrix.data(), is(equalTo(expected)));
  }

  @Test
  public void whenVectorsAddedThenSumCorrect() {
    Vector sum = vec1.plus(vec3);
    Vector expected = new Vector(9.0, 6.5, 17.5);
    assertThat(sum, is(equalTo(expected)));
  }

  @Test
  public void whenVectorsSubtractedThenDiffCorrect() {
    Vector diff = vec3.minus(vec1);
    Vector expected = new Vector(3.0, -1.5, 2.5);
    assertThat(diff, is(equalTo(expected)));
  }

  @Test
  public void whenVectorSubtractedByScalarThenDiffCorrect() {
    Vector diff = vec3.minus(2.0);
    Vector expected = new Vector(4.0, 0.5, 8.0);
    assertThat(diff, is(equalTo(expected)));
  }

}

@@ -153,20 +153,85 @@
 g.junit.
-Test
+Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException
 ;%0A%0Apubli
@@ -328,16 +328,90 @@
  vec3;%0A%0A
+  @Rule%0A  public ExpectedException exception = ExpectedException.none();%0A%0A
   @Befor
@@ -566,16 +566,893 @@
 .0);%0A  %7D
+%0A%0A  @Test%0A  public void whenAxpyThenResultCorrect() %7B%0A    Vector result = vec1.axpy(vec3, 5.0);%0A    Vector expected = new Vector(21.0, 22.5, 47.5);%0A    assertThat(result, is(equalTo(expected)));%0A  %7D%0A%0A  @Test%0A  public void whenSumThenResultCorrect() %7B%0A    double result = vec1.sum();%0A    assertThat(result, is(equalTo(14.5)));%0A    result = vec1.sumOfSquares();%0A    assertThat(result, is(equalTo(81.25)));%0A  %7D%0A%0A  @Test%0A  public void whenEqualsAndHashCodeThenValuesCorrect() %7B%0A    assertThat(vec1.equals(vec2), is(false));%0A    assertThat(vec1.hashCode(), is(not(vec2.hashCode())));%0A    Vector newVec = new Vector(3.0, 4.0, 7.5);%0A    assertThat(vec1.equals(newVec), is(true));%0A    assertThat(vec1.hashCode(), is(newVec.hashCode()));%0A    assertThat(vec1.equals(new Object()), is(false));%0A    assertThat(vec1.equals(null), is(false));%0A    assertThat(vec1.equals(vec1), is(true));%0A  %7D
 %0A  %0A  @T
@@ -1731,37 +1731,230 @@
 To(expected)));%0A
-
   %7D%0A%0A
+  @Test%0A  public void whenDotProductZeroLengthVectorExceptionThrown() %7B%0A    Vector empty = new Vector();%0A    exception.expect(IllegalArgumentException.class);%0A    vec1.dotProduct(empty);%0A  %7D%0A%0A%0A
   @Test%0A  public

Add tests for linear.doubles Vector