Sha256: dcfe941bc3935f0ac06df5415c57f3a937e1f565724b26e16616185dca21ecfc

Contents?: true

Size: 1.96 KB

Versions: 125

Compression:

Stored size: 1.96 KB

Contents

var Zipper = require('./zipper');

// Tests adapted from `problem-specifications/zipper/canonical-data.json` @ v1.0.0

function bt(value, left, right) {
  return {
    value: value,
    left: left,
    right: right
  };
}

function leaf(value) {
  return bt(value, null, null);
}

describe('Zipper', function () {
  var t1 = bt(1, bt(2, null, leaf(3)), leaf(4));
  var t2 = bt(1, bt(5, null, leaf(3)), leaf(4));
  var t3 = bt(1, bt(2, leaf(5), leaf(3)), leaf(4));
  var t4 = bt(1, leaf(2), leaf(4));
  var t5 = bt(1, bt(2, null, leaf(3)), bt(6, leaf(7), leaf(8)));
  var t6 = bt(1, bt(2, null, leaf(5)), leaf(4));
  var zipper;

  beforeEach(function () {
    zipper = Zipper.fromTree(t1);
  });

  it('data is retained', function () {
    expect(zipper.toTree(t1)).toEqual(t1);
  });

  xit('left, right and value', function () {
    expect(zipper.left().right().value()).toEqual(3);
  });

  xit('dead end', function () {
    expect(zipper.left().left()).toBe(null);
  });

  xit('tree from deep focus', function () {
    expect(zipper.left().right().toTree()).toEqual(t1);
  });

  xit('traversing up from top', function () {
    expect(zipper.up()).toEqual(null);
  });

  xit('left, right and up', function () {
    expect(zipper.left().up().right().up().left().right().value()).toEqual(3);
  });

  xit('setValue', function () {
    expect(zipper.left().setValue(5).toTree()).toEqual(t2);
  });

  xit('setValue after traversing up', function () {
    expect(zipper.left().right().up().setValue(5).toTree()).toEqual(t2);
  });

  xit('setLeft with leaf', function () {
    expect(zipper.left().setLeft(leaf(5)).toTree()).toEqual(t3);
  });

  xit('setRight with null', function () {
    expect(zipper.left().setRight(null).toTree()).toEqual(t4);
  });

  xit('setRight with subtree', function () {
    expect(zipper.setRight(bt(6, leaf(7), leaf(8))).toTree()).toEqual(t5);
  });

  xit('setValue on deep focus', function () {
    expect(zipper.left().right().setValue(5).toTree()).toEqual(t6);
  });
});

Version data entries

125 entries across 125 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.77 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.76 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.75 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.74 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.73 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.72 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.71 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.70 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.69 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.68 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.67 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.66 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.65 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.64 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.63 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.62 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.61 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.60 tracks/javascript/exercises/zipper/zipper.spec.js
trackler-2.2.1.59 tracks/javascript/exercises/zipper/zipper.spec.js