metadata.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var Memoizerific = require('../src/memoizerific');
  2. describe("wasMemoized", () => {
  3. var memoizedFn;
  4. beforeEach(function() {
  5. memoizedFn = Memoizerific(50)(function(arg1, arg2, arg3) {
  6. return arg1.num * arg2.num;
  7. });
  8. });
  9. it("should be false before any invocations", () => {
  10. expect(memoizedFn.wasMemoized).toEqual(false);
  11. });
  12. it("should be false after one invocation", () => {
  13. memoizedFn(1, 2, 3);
  14. expect(memoizedFn.wasMemoized).toEqual(false);
  15. });
  16. it("should be true", () => {
  17. memoizedFn(1, 2, 3);
  18. memoizedFn(1, 2, 3);
  19. expect(memoizedFn.wasMemoized).toEqual(true);
  20. });
  21. it("should be false", () => {
  22. memoizedFn(1, 2, 3);
  23. memoizedFn(1, 2, 3);
  24. memoizedFn(4, 5, 6);
  25. expect(memoizedFn.wasMemoized).toEqual(false);
  26. });
  27. });
  28. describe("limit", () => {
  29. var memoizedFn;
  30. beforeEach(function() {
  31. memoizedFn = Memoizerific(43)(function(arg1, arg2, arg3) {
  32. return arg1.num * arg2.num;
  33. });
  34. });
  35. it("should be correct after no invocations", () => {
  36. expect(memoizedFn.limit).toEqual(43);
  37. });
  38. it("should be correct after one invocation", () => {
  39. memoizedFn(1, 2, 3);
  40. expect(memoizedFn.limit).toEqual(43);
  41. });
  42. it("should be correct after multiple invocations", () => {
  43. memoizedFn(1, 2, 3);
  44. memoizedFn(4, 5, 6);
  45. expect(memoizedFn.limit).toEqual(43);
  46. });
  47. });