<commit_before>
describe("Lists", function(){

   function assertEquals(expected, actual) {
      expect(actual).toEqual(expected);
   }


   it("can use cons, head and tail", function() {
      var emptyList = emptyList;
      
      var listA   = cons('a', emptyList);
      var listBA  = cons('b', listA);
      var listCBA = cons('c', listBA);
      
      expect(head(listCBA)).toBe('c');
      expect(head(tail(listCBA))).toBe('b'); 
      expect(head(tail(tail(listCBA)))).toBe('a');
   });


   it("can convert to an array", function() {
   
      var listCBA = cons('c', cons('b', cons('a', emptyList)));
      
      assertEquals(['c','b','a'], listAsArray(listCBA));   
   })

});

(function(){

   function TestCase(name, tests){}

   TestCase("listsTest", {
   
           
      testListAsArrayCanHandleEmptyList: function() {
               
         assertEquals([], listAsArray(emptyList));
      }      
      
   ,      
      testReversingLists: function() {
      
         var listCBA = cons('c', cons('b', cons('a', emptyList)));
         
         assertEquals(['a','b','c'], listAsArray(reverseList(listCBA)));
      }
      
   ,  testMap: function() {
         var naturals = cons(1, cons(2, cons(3, emptyList)));
         var evens = cons(2, cons(4, cons(6, emptyList)));
         
         function doubleIt(n){return n * 2}
         
         assertEquals(evens, map(doubleIt, naturals));
      }      
      
   ,  testAsListWithNonEmptyList: function() {
         assertEquals(['a','b','c'], listAsArray( asList(['a','b','c']) )  );
      }
      
   ,  testAsListWithEmptyList: function() {
         assertEquals([], listAsArray( asList([]) )  );
      }            

   ,  testListEvery: function() {
         var l = list(1,2,3,4,5,6,7,8,9,10);
         
         function isANumber(n) {
            return typeof n == 'number';
         }
         
         function isOdd(n) {
            return n % 2 == 0;
         }
         
         function isLessThanTen(n) {
            return n < 10;
         }
         
         function isLessThanOrEqualToTen(n) {
            return n <= 10;
         }                           
         
         assertTrue(  listEvery(isANumber,                l ));
         assertFalse( listEvery(isOdd,                    l ));
         assertFalse( listEvery(isLessThanTen,            l ));
         assertTrue(  listEvery(isLessThanOrEqualToTen,   l ));

      }                        
      
   ,  'testFoldListWhereOrderDoesntMatter': function() {
         function add(n, m){ return n+m }
         
         var sum = foldR(add, 0, list(1,2,3,4));
         
         assertEquals(10, sum);
      }
      
   ,  'testFoldListUsesStartValue': function() {
         function divide(n, m){ return n / m }
         
         var result = foldR(divide, 100, list(2, 2));
         
         //   (100/2) / 2  = 25 
         
         assertEquals(25, result);
      }
      
   ,  'testFoldOrder': function() {
         function functionString(stringSoFar, fnName){ return fnName + '(' + stringSoFar + ')' }
         
         var functionStringResult = foldR(functionString, 'x', list('a', 'b', 'c'));
         
         // if order were wrong, might give c(b(a(x)))
                  
         assertEquals('a(b(c(x)))', functionStringResult);
      }                    
   
   });

})();<commit_msg>convert tests to jasmine<commit_after>
describe("Lists", function(){

   function assertEquals(expected, actual) {
      expect(actual).toEqual(expected);
   }
   
   function assertTrue(actual) {
      expect(actual).toBe(true);
   }
   
   function assertFalse(actual) {
      expect(actual).toBe(false);
   }   

   it("can use cons, head and tail", function() {
      var emptyList = emptyList;
      
      var listA   = cons('a', emptyList);
      var listBA  = cons('b', listA);
      var listCBA = cons('c', listBA);
      
      expect(head(listCBA)).toBe('c');
      expect(head(tail(listCBA))).toBe('b'); 
      expect(head(tail(tail(listCBA)))).toBe('a');
   });


   it("can convert to an array", function() {
   
      var listCBA = cons('c', cons('b', cons('a', emptyList)));
      
      assertEquals(['c','b','a'], listAsArray(listCBA));   
   });
   
   it("can convert empty list to an array", function(){
      assertEquals([], listAsArray(emptyList));
   });
   
   it("can reverse the order of a list", function() {
      var listCBA = cons('c', cons('b', cons('a', emptyList)));
               
      assertEquals(['a','b','c'], listAsArray(reverseList(listCBA)));   
   });
   
   it("can map over a list", function() {
      var naturals = cons(1, cons(2, cons(3, emptyList)));
      var evens = cons(2, cons(4, cons(6, emptyList)));
      
      function doubleIt(n){return n * 2}
      
      assertEquals(evens, map(doubleIt, naturals));
   });
   
   it("can convert non empty list to an array", function(){
      assertEquals(['a','b','c'], listAsArray( asList(['a','b','c']) )  );
   });
   
   it("can convert empty array to list", function() {
      assertEquals([], listAsArray( asList([]) )  );
   });
   
   it("can assert every item in a list holds for a given test", function(){
      var l = list(1,2,3,4,5,6,7,8,9,10);
               
      function isANumber(n) {
         return typeof n == 'number';
      }
      
      function isOdd(n) {
         return n % 2 == 0;
      }
      
      function isLessThanTen(n) {
         return n < 10;
      }
      
      function isLessThanOrEqualToTen(n) {
         return n <= 10;
      }                           
      
      assertTrue(  listEvery(isANumber,                l ));
      assertFalse( listEvery(isOdd,                    l ));
      assertFalse( listEvery(isLessThanTen,            l ));
      assertTrue(  listEvery(isLessThanOrEqualToTen,   l ));   
   });
   
   it("can fold list where order doesnt matter", function(){
      function add(n, m){ return n+m }
      
      var sum = foldR(add, 0, list(1,2,3,4));
      
      assertEquals(10, sum);   
   });
   
   it("can fold list where start value matters", function(){
      function divide(n, m){ return n / m }
      
      var result = foldR(divide, 100, list(2, 2));
      
      //   (100/2) / 2  = 25       
      assertEquals(25, result);   
   });

   it("can fold list in the correct order", function(){
      function functionString(stringSoFar, fnName){ return fnName + '(' + stringSoFar + ')' }
      
      var functionStringResult = foldR(functionString, 'x', list('a', 'b', 'c'));
      
      // if order were wrong, might give c(b(a(x)))
               
      assertEquals('a(b(c(x)))', functionStringResult);   
   });
});
{'fraction_non_alphanumeric': 0.1545372866127583, 'fraction_numerical': 0.013477088948787063, 'mean_word_length': 1.8838514680483593, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4518673', 'n_tokens_mistral': 2118, 'n_tokens_neox': 2046, 'n_words': 445}