| 
          var exercise = require('./functional'); | 
        
        
           | 
          
 | 
        
        
           | 
          describe('factorial', function() { | 
        
        
           | 
            'use strict'; | 
        
        
           | 
          
 | 
        
        
           | 
            var factorial; | 
        
        
           | 
            beforeEach(function() { | 
        
        
           | 
              factorial = exercise.factorial; | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            it('is a function', function() { | 
        
        
           | 
              expect(factorial).toEqual(jasmine.any(Function)); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            it('computes the correct value', function() { | 
        
        
           | 
              expect(factorial(5)).toEqual(120); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            describe('given 0', function() { | 
        
        
           | 
              it('should return 1', function() { | 
        
        
           | 
                expect(factorial(0)).toEqual(1); | 
        
        
           | 
              }); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            describe('given 1', function() { | 
        
        
           | 
              it('should return 1', function() { | 
        
        
           | 
                expect(factorial(1)).toEqual(1); | 
        
        
           | 
              }); | 
        
        
           | 
            }); | 
        
        
           | 
          }); | 
        
        
           | 
          
 | 
        
        
           | 
          describe('memoize', function() { | 
        
        
           | 
            'use strict'; | 
        
        
           | 
            var memoize; | 
        
        
           | 
            beforeEach(function() { | 
        
        
           | 
              memoize = exercise.memoize; | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            it('is a function', function() { | 
        
        
           | 
              expect(memoize).toEqual(jasmine.any(Function)); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            it('returns a function', function() { | 
        
        
           | 
              expect(memoize(function() {})).toEqual(jasmine.any(Function)); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            describe('the returned function', function() { | 
        
        
           | 
              var returnedFunc; | 
        
        
           | 
              beforeEach(function() { | 
        
        
           | 
                returnedFunc = memoize(function(num1, num2) { | 
        
        
           | 
                  return num1 + num2; | 
        
        
           | 
                }); | 
        
        
           | 
              }); | 
        
        
           | 
          
 | 
        
        
           | 
              describe('given parameters that it has not been seen', function() { | 
        
        
           | 
                it('returns false', function() { | 
        
        
           | 
                  expect(returnedFunc(1, 2)).toEqual(false); | 
        
        
           | 
                }); | 
        
        
           | 
              }); | 
        
        
           | 
          
 | 
        
        
           | 
              describe('given parameters that it has already seen', function() { | 
        
        
           | 
                beforeEach(function() { | 
        
        
           | 
                  returnedFunc(1, 2); | 
        
        
           | 
                }); | 
        
        
           | 
          
 | 
        
        
           | 
                it('returns true', function() { | 
        
        
           | 
                  expect(returnedFunc(1, 2)).toEqual(true); | 
        
        
           | 
                }); | 
        
        
           | 
              }); | 
        
        
           | 
            }); | 
        
        
           | 
          }); | 
        
        
           | 
          
 | 
        
        
           | 
          // average tests are not exhaustive as the parameter values could be given in many different combinations | 
        
        
           | 
          describe('average', function() { | 
        
        
           | 
            'use strict'; | 
        
        
           | 
            var average; | 
        
        
           | 
            beforeEach(function() { | 
        
        
           | 
              average = exercise.average; | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            it('is a function', function() { | 
        
        
           | 
              expect(average).toEqual(jasmine.any(Function)); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            describe('when taking 1 parameter', function() { | 
        
        
           | 
              it('returns a function', function() { | 
        
        
           | 
                expect(average(1)).toEqual(jasmine.any(Function)); | 
        
        
           | 
              }); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            describe('when taking 2 parameters', function() { | 
        
        
           | 
              it('returns a function on the first call', function() { | 
        
        
           | 
                expect(average(1, 2)).toEqual(jasmine.any(Function)); | 
        
        
           | 
              }); | 
        
        
           | 
          
 | 
        
        
           | 
              describe('in two separate calls', function() { | 
        
        
           | 
                it('returns a function on the first and second call', function() { | 
        
        
           | 
                  expect(average(1)(2)).toEqual(jasmine.any(Function)); | 
        
        
           | 
                }); | 
        
        
           | 
              }); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            describe('when taking 3 parameters', function() { | 
        
        
           | 
              it('returns the proper result', function() { | 
        
        
           | 
                expect(average(3, 6, 9)).toEqual(6); | 
        
        
           | 
              }); | 
        
        
           | 
          
 | 
        
        
           | 
              describe('in two separate calls', function() { | 
        
        
           | 
                it('returns the proper result taking 2 parameters and then 1 parameter', function() { | 
        
        
           | 
                  expect(average(3, 6)(9)).toEqual(6); | 
        
        
           | 
                }); | 
        
        
           | 
          
 | 
        
        
           | 
                it('returns the proper result taking 1 and 2 parameters', function() { | 
        
        
           | 
                  expect(average(9)(3, 6)).toEqual(6); | 
        
        
           | 
                }); | 
        
        
           | 
              }); | 
        
        
           | 
          
 | 
        
        
           | 
              describe('in three separate calls', function() { | 
        
        
           | 
                it('returns a the proper result', function() { | 
        
        
           | 
                  expect(average(9)(3)(6)).toEqual(6); | 
        
        
           | 
                }); | 
        
        
           | 
              }); | 
        
        
           | 
            }); | 
        
        
           | 
          }); | 
        
        
           | 
          
 | 
        
        
           | 
          describe('inject', function() { | 
        
        
           | 
            'use strict'; | 
        
        
           | 
          
 | 
        
        
           | 
            var inject; | 
        
        
           | 
            beforeEach(function() { | 
        
        
           | 
              inject = exercise.inject; | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            it('is a function', function() { | 
        
        
           | 
              expect(inject).toEqual(jasmine.any(Function)); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            it('reduces to a proper value', function() { | 
        
        
           | 
              var sum = inject(0).reduce([1, 2, 3, 6], function(sum, value) { return sum + value; }); | 
        
        
           | 
              expect(sum).toEqual(12); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            it('reduces to a proper value', function() { | 
        
        
           | 
              var product = inject(1).reduce([4, 3, 2, 6], function(product, value) { | 
        
        
           | 
                return product * value; | 
        
        
           | 
              }); | 
        
        
           | 
          
 | 
        
        
           | 
              expect(product).toEqual(144); | 
        
        
           | 
            }); | 
        
        
           | 
          
 | 
        
        
           | 
            describe('the returned object', function() { | 
        
        
           | 
              it('has a reduce method', function() { | 
        
        
           | 
                expect(inject(0)).toEqual({ reduce: jasmine.any(Function) }); | 
        
        
           | 
              }); | 
        
        
           | 
            }); | 
        
        
           | 
          }); |