<commit_before>describe('pivot', function () {
  var sample_csv, sample_fields;

  beforeEach(function () {
      sample_csv =  "last_name,first_name,zip_code,billed_amount\n" +
                    "Jackson,Robert,34471,100.00\n" +
                    "Smith,Jon,34471,173.20\n" +
                    "Jackson,Jon,34474,262.42\n" +
                    "Jackson,Susan,34476,7.45\n" +
                    "Fornea,Chris,34474,62.98\n" +
                    "Fornea,Shelly,39401,124.63"

      sample_fields = [
        {name: 'first_name', type: 'string',  filterable: true},
        {name: 'zip_code',   type: 'integer', filterable: true},
        {name: 'pseudo_zip', type: 'integer', filterable: true, pseudo: true, pseudoFunction: function(row){ return row.zip_code + 1}},
        {name: 'billed_amount',   type: 'float', labelable: false, summarizable: true,
                summarizeFunction: function(rows){
                  var runningTotal = 0;
                  for (var i = 0; i < rows.length; i++) {
                    runningTotal += rows[i].billed_amount;
                  };

                  return runningTotal;
                }
        }
      ]

      pivot.fields().set(sample_fields);
      pivot.csv(sample_csv);
    });

  afterEach(function () {
    pivot.reset();
  });

  describe('CSV', function () {
    it('can parse csv into an array', function(){
      expect(pivot.data().raw[0]).toEqual({last_name:'Jackson',first_name:'Robert',zip_code: 34471, billed_amount: 100, pseudo_zip: 34472});
      expect(pivot.data().raw.length).toEqual(6)
    });

    it('can filter items from csv', function() {
      expect(pivot.data().raw.length).toEqual(6);

      // apply filter
      pivot.filters().apply({last_name: 'Jackson'});
      expect(pivot.data().all.length).toEqual(3);
    });
  });

  describe('Filters', function() {
    beforeEach(function () {
      pivot.filters().set({last_name: 'Jackson'});
    });

    it('force type specifity on new filters', function(){
      pivot.filters().add({zip_code: '34471'})
      expect(pivot.filters().all.zip_code).toEqual(34471)
    });

    it('narrows filter and resets when filter chain is altered', function(){
      expect(pivot.data().all.length).toEqual(0);

      // apply filter
      pivot.filters().apply();
      expect(pivot.data().all.length).toEqual(3);

      // apply additional filter
      pivot.filters().add({first_name: 'Jon'});

      // with no params simply runs existing filters
      pivot.filters().apply()
      expect(pivot.data().all.length).toEqual(1);

      // reset original filter
      pivot.filters().apply({last_name: 'Fornea'});
      expect(pivot.data().all.length).toEqual(2);
    });
  });

  describe('Fields', function(){
    it('allows the specification of fields', function(){
      expect(pivot.fields().get('zip_code').type).toEqual("integer");
      expect(pivot.fields().get('zip_code').filterable).toBeTruthy();
    });

    it('allows for adding fields', function(){
      expect(pivot.fields().all().length).toEqual(5);
      pivot.fields().add({name:"not_a_real_fields", type: 'date', filterable: true})
      expect(pivot.fields().all().length).toEqual(6);
    });

    describe('Pseudo Fields', function(){
      it('allows creating pseudo fields', function(){
        expect(pivot.data().raw[0].pseudo_zip).toEqual(34472);
      });

      it('captures values for filterable pseudo fields', function(){
        expect(Object.keys(pivot.fields().pseudo[0].values).length).toEqual(4);
      });
    });
  });

  describe('Display', function(){
    it('should allow set/get of label fields', function(){
      pivot.display().label().set(['last_name']);
      expect(Object.keys(pivot.display().label().get)).toEqual(['last_name']);
    });

    it('should allow set/get of summary fields', function(){
      pivot.display().summary().set(['last_name']);
      expect(Object.keys(pivot.display().summary().get)).toEqual(['last_name']);
    });
  });

  describe('Results', function(){
    it('should only return label fields that were selected', function(){
      pivot.display().label().set(['last_name']);
      expect(pivot.results()['last_name:Jackson|'].last_name).toEqual('Jackson');
      expect(pivot.results()['last_name:Fornea|'].last_name).toEqual('Fornea');
      expect(pivot.results()['last_name:Smith|'].zip_code).toEqual(undefined);

      pivot.display().label().set(['last_name', 'zip_code']);
      expect(pivot.results()['last_name:Jackson|zip_code:34471|'].last_name).toEqual('Jackson');
      expect(pivot.results()['last_name:Fornea|zip_code:34474|'].zip_code).toEqual(34474);
    });

    it('should only return summary fields that were selected', function(){
      pivot.display().label().set(['last_name']);
      pivot.display().summary().set([]);

      expect(pivot.results()['last_name:Jackson|'].billed_amount).toEqual(undefined);

      pivot.display().summary().set(['billed_amount']);
      expect(pivot.results()['last_name:Jackson|'].billed_amount).toEqual(369.87);
    });
  });
});<commit_msg>Add test to make sure display().set() clears any current fields.<commit_after>describe('pivot', function () {
  var sample_csv, sample_fields;

  beforeEach(function () {
      sample_csv =  "last_name,first_name,zip_code,billed_amount\n" +
                    "Jackson,Robert,34471,100.00\n" +
                    "Smith,Jon,34471,173.20\n" +
                    "Jackson,Jon,34474,262.42\n" +
                    "Jackson,Susan,34476,7.45\n" +
                    "Fornea,Chris,34474,62.98\n" +
                    "Fornea,Shelly,39401,124.63"

      sample_fields = [
        {name: 'first_name', type: 'string',  filterable: true},
        {name: 'zip_code',   type: 'integer', filterable: true},
        {name: 'pseudo_zip', type: 'integer', filterable: true, pseudo: true, pseudoFunction: function(row){ return row.zip_code + 1}},
        {name: 'billed_amount',   type: 'float', labelable: false, summarizable: true,
                summarizeFunction: function(rows){
                  var runningTotal = 0;
                  for (var i = 0; i < rows.length; i++) {
                    runningTotal += rows[i].billed_amount;
                  };

                  return runningTotal;
                }
        }
      ]

      pivot.fields().set(sample_fields);
      pivot.csv(sample_csv);
    });

  afterEach(function () {
    pivot.reset();
  });

  describe('CSV', function () {
    it('can parse csv into an array', function(){
      expect(pivot.data().raw[0]).toEqual({last_name:'Jackson',first_name:'Robert',zip_code: 34471, billed_amount: 100, pseudo_zip: 34472});
      expect(pivot.data().raw.length).toEqual(6)
    });

    it('can filter items from csv', function() {
      expect(pivot.data().raw.length).toEqual(6);

      // apply filter
      pivot.filters().apply({last_name: 'Jackson'});
      expect(pivot.data().all.length).toEqual(3);
    });
  });

  describe('Filters', function() {
    beforeEach(function () {
      pivot.filters().set({last_name: 'Jackson'});
    });

    it('force type specifity on new filters', function(){
      pivot.filters().add({zip_code: '34471'})
      expect(pivot.filters().all.zip_code).toEqual(34471)
    });

    it('narrows filter and resets when filter chain is altered', function(){
      expect(pivot.data().all.length).toEqual(0);

      // apply filter
      pivot.filters().apply();
      expect(pivot.data().all.length).toEqual(3);

      // apply additional filter
      pivot.filters().add({first_name: 'Jon'});

      // with no params simply runs existing filters
      pivot.filters().apply()
      expect(pivot.data().all.length).toEqual(1);

      // reset original filter
      pivot.filters().apply({last_name: 'Fornea'});
      expect(pivot.data().all.length).toEqual(2);
    });
  });

  describe('Fields', function(){
    it('allows the specification of fields', function(){
      expect(pivot.fields().get('zip_code').type).toEqual("integer");
      expect(pivot.fields().get('zip_code').filterable).toBeTruthy();
    });

    it('allows for adding fields', function(){
      expect(pivot.fields().all().length).toEqual(5);
      pivot.fields().add({name:"not_a_real_fields", type: 'date', filterable: true})
      expect(pivot.fields().all().length).toEqual(6);
    });

    describe('Pseudo Fields', function(){
      it('allows creating pseudo fields', function(){
        expect(pivot.data().raw[0].pseudo_zip).toEqual(34472);
      });

      it('captures values for filterable pseudo fields', function(){
        expect(Object.keys(pivot.fields().pseudo[0].values).length).toEqual(4);
      });
    });
  });

  describe('Display', function(){
    it('should allow set/get of label fields', function(){
      pivot.display().label().set(['last_name']);
      expect(Object.keys(pivot.display().label().get)).toEqual(['last_name']);
    });

    it('should allow set/get of summary fields', function(){
      pivot.display().summary().set(['last_name']);
      expect(Object.keys(pivot.display().summary().get)).toEqual(['last_name']);
    });

    it('should reset summary fields on subsequent calls', function(){
      pivot.display().summary().set(['last_name']);
      expect(Object.keys(pivot.display().summary().get)).toEqual(['last_name']);

      pivot.display().summary().set(['first_name']);
      expect(Object.keys(pivot.display().summary().get)).toEqual(['first_name']);
    });
  });

  describe('Results', function(){
    it('should only return label fields that were selected', function(){
      pivot.display().label().set(['last_name']);
      expect(pivot.results()['last_name:Jackson|'].last_name).toEqual('Jackson');
      expect(pivot.results()['last_name:Fornea|'].last_name).toEqual('Fornea');
      expect(pivot.results()['last_name:Smith|'].zip_code).toEqual(undefined);

      pivot.display().label().set(['last_name', 'zip_code']);
      expect(pivot.results()['last_name:Jackson|zip_code:34471|'].last_name).toEqual('Jackson');
      expect(pivot.results()['last_name:Fornea|zip_code:34474|'].zip_code).toEqual(34474);
    });

    it('should only return summary fields that were selected', function(){
      pivot.display().label().set(['last_name']);
      pivot.display().summary().set([]);

      expect(pivot.results()['last_name:Jackson|'].billed_amount).toEqual(undefined);

      pivot.display().summary().set(['billed_amount']);
      expect(pivot.results()['last_name:Jackson|'].billed_amount).toEqual(369.87);
    });
  });
});
{'fraction_non_alphanumeric': 0.18622327790973872, 'fraction_numerical': 0.022992874109263657, 'mean_word_length': 3.1654135338345863, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2184673', 'n_tokens_mistral': 3421, 'n_tokens_neox': 3188, 'n_words': 497}