UNB/ CS/ David Bremner/ teaching/ cs2613/ assignments/ CS2613 Assignment 3

What to hand in, and how to hand it in

Marking

Part 1: Flatten

Write a function flatten that produces an array containing all of the elements of all of the nested arrays in an array. For full marks your solution should use recursion. Your function should pass the following jasmine tests

describe("flatten",
     function () {
         it("base case",
        function () {
            expect(ms.flatten([])).toEqual([]);
        });
         it("single element",
        function () {
            expect(ms.flatten([1])).toEqual([1]);
            expect(ms.flatten(["foo"])).toEqual(["foo"]);
            expect(ms.flatten([{foo: 1}])).toEqual([{foo: 1}]);                     
        });
         it("longer list, no mutation",
        function () {
            var data = [[[1],2,[3]],4,[5,6]];
            var orig_data = data;
            expect(ms.flatten(data)).toEqual([1,2,3,4,5,6]);
            expect(data).toEqual(orig_data);
        });
     });

Part 2: Mail Summarize, Again

describe("summarize_mail",
     function() {
         it("no headers",
        function () {
            expect(ms.summarize_mail("example1.json")).toEqual([{}, {}, {}]);
            expect(ms.summarize_mail("example2.json")).toEqual(Array(10).fill({}));
        });
         it("Subject",
        function () {
            expect(ms.summarize_mail("example1.json",'Subject')).toEqual([{Subject: "[notmuch] archive"},
                                          {Subject: "Re: [notmuch] archive"},
                                          {Subject: "Re: [notmuch] archive"}]);
        });
         it("Subject, Date",
        function () {
            expect(ms.summarize_mail("example1.json",'Subject','Date')).toEqual(
            [{Subject: "[notmuch] archive", Date: 'Tue, 17 Nov 2009 18:21:38 -0500'},
             {Subject: "Re: [notmuch] archive", Date: 'Tue, 17 Nov 2009 18:04:31 -0800'},
             {Subject: "Re: [notmuch] archive", Date: 'Wed, 18 Nov 2009 02:22:12 -0800'}]);
        });
     });

Part 3: Testing

Impliment (and explain in your commit message) two improvements to the test suite for summarize_email.