Skip to content

Instantly share code, notes, and snippets.

@whitelizard
Created November 18, 2019 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whitelizard/f03b6515eedf5776a058b87c32c2820c to your computer and use it in GitHub Desktop.
Save whitelizard/f03b6515eedf5776a058b87c32c2820c to your computer and use it in GitHub Desktop.
Factory pattern tests
const c1 = makeCircle([2.5, 0], 1.5);
const c2 = makeCircle([-2, 0], 2);
c1.area(); // -> 7.0685834705770345
c2.area(); // -> 12.566370614359172
c1.intersect(c2); // -> false
c1.getHits(); // -> 0
c1.pos[0] = 1;
c1.intersect(c2); // -> true
c1.getHits(); // -> 1
c2.getHits(); // -> 1
c1.hits = 4; // OK, but this just creates a "dead" variable on the object, not used internally
c1.getHits(); // -> 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment