import Hexagon from "../../../src/modules/shapes/Hexagon";
import Shape from "../../../src/modules/shapes/Shape";
import chai from "chai";
const expect = chai.expect;

describe("Hexagon", () => {
  it("should extend Shape", () => {
    const hex = new Hexagon(0, 0, 1);
    expect(hex instanceof Shape).to.be.true;
  });

  it("should be instantiable with x,y coordinates and a radius", () => {
    const hex = new Hexagon(10, 12, 2);
    expect(hex.center).to.deep.equal({x: 10, y: 12});
    expect(hex.radius).to.equal(2);
  });

  it("can calculate the position of each of its corners", () => {
    const x = 5;
    const y = 10;
    const radius = 3;
    const hex = new Hexagon(x, y, radius);

    expect(hex.cornerAt(0).x).to.equal(x + radius * Math.cos(Math.PI / 180 * 0));
    expect(hex.cornerAt(0).y).to.equal(y + radius * Math.sin(Math.PI / 180 * 0));
    expect(hex.cornerAt(1).x).to.equal(x + radius * Math.cos(Math.PI / 180 * -60));
    expect(hex.cornerAt(1).y).to.equal(y + radius * Math.sin(Math.PI / 180 * -60));
    expect(hex.cornerAt(2).x).to.equal(x + radius * Math.cos(Math.PI / 180 * -120));
    expect(hex.cornerAt(2).y).to.equal(y + radius * Math.sin(Math.PI / 180 * -120));
    expect(hex.cornerAt(3).x).to.equal(x + radius * Math.cos(Math.PI / 180 * -180));
    expect(hex.cornerAt(3).y).to.equal(y + radius * Math.sin(Math.PI / 180 * -180));
    expect(hex.cornerAt(4).x).to.equal(x + radius * Math.cos(Math.PI / 180 * -240));
    expect(hex.cornerAt(4).y).to.equal(y + radius * Math.sin(Math.PI / 180 * -240));
    expect(hex.cornerAt(5).x).to.equal(x + radius * Math.cos(Math.PI / 180 * -300));
    expect(hex.cornerAt(5).y).to.equal(y + radius * Math.sin(Math.PI / 180 * -300));
  });

  it("can calculate its bounding box's height and width", () => {
    const x = 2;
    const y = 8;
    const radius = 5;
    const hex = new Hexagon(x, y, radius);

    expect(hex.width).to.equal(radius * 2);
    expect(hex.height).to.equal(Math.sqrt(3) / 2 * hex.width);
  });
});

@@ -189,16 +189,48 @@
 () =%3E %7B%0A
+  const errorMargin = 0.00001;%0A%0A
   it(%22sh
@@ -761,136 +761,107 @@
 .to.
-equal(x + radius * Math.cos(Math.PI / 180 * 0));%0A    expect(hex.cornerAt(0).y).to.equal(y + radius * Math.sin(Math.PI / 180 * 0)
+be.closeTo(7.99999, errorMargin);%0A    expect(hex.cornerAt(0).y).to.be.closeTo(10.00000, errorMargin
 );%0A 
@@ -896,56 +896,39 @@
 .to.
+b
 e
-qual(x + radius * Math
 .c
+l
 os
-(Math.PI / 180 * -60)
+eTo(6.50000, errorMargin
 );%0A 
@@ -963,56 +963,39 @@
 .to.
-equal(y + radius * Math.sin(Math.PI / 180 * -60)
+be.closeTo(7.40192, errorMargin
 );%0A 
@@ -1030,57 +1030,39 @@
 .to.
+b
 e
-qual(x + radius * Math
 .c
+l
 os
-(Math.PI / 180 * -120)
+eTo(3.50000, errorMargin
 );%0A 
@@ -1097,57 +1097,39 @@
 .to.
-equal(y + radius * Math.sin(Math.PI / 180 * -120)
+be.closeTo(7.40192, errorMargin
 );%0A 
@@ -1164,57 +1164,39 @@
 .to.
+b
 e
-qual(x + radius * Math
 .c
+l
 os
-(Math.PI / 180 * -180)
+eTo(2.00000, errorMargin
 );%0A 
@@ -1231,57 +1231,40 @@
 .to.
-equal(y + radius * Math.sin(Math.PI / 180 * -180)
+be.closeTo(10.00000, errorMargin
 );%0A 
@@ -1299,57 +1299,39 @@
 .to.
+b
 e
-qual(x + radius * Math
 .c
+l
 os
-(Math.PI / 180 * -240)
+eTo(3.50000, errorMargin
 );%0A 
@@ -1366,57 +1366,40 @@
 .to.
-equal(y + radius * Math.sin(Math.PI / 180 * -240)
+be.closeTo(12.59807, errorMargin
 );%0A 
@@ -1434,57 +1434,39 @@
 .to.
+b
 e
-qual(x + radius * Math
 .c
+l
 os
-(Math.PI / 180 * -300)
+eTo(6.50000, errorMargin
 );%0A 
@@ -1501,57 +1501,40 @@
 .to.
-equal(y + radius * Math.sin(Math.PI / 180 * -300)
+be.closeTo(12.59807, errorMargin
 );%0A 
@@ -1613,69 +1613,140 @@
     
-const x = 2;%0A    const y = 8;%0A    const radius = 5;%0A    const
+let hex = new Hexagon(2, 8, 5);%0A    expect(hex.width).to.equal(10);%0A    expect(hex.height).to.be.closeTo(8.66025, errorMargin);%0A%0A   
  hex
@@ -1760,32 +1760,27 @@
 Hexagon(
-x, y, radius
+0, 0, 10
 );%0A
-%0A
     expe
@@ -1806,18 +1806,10 @@
 ual(
-radius * 
 2
+0
 );%0A 
@@ -1837,42 +1837,40 @@
 .to.
-equal(Math.sqrt(3) / 2 * hex.width
+be.closeTo(17.32050, errorMargin
 );%0A 

Refactor Hexagon tests to compare against hand-computed value Before it was comparing the calculation to the same calculation...of course those are going to be equal, so the test was pointless.