test("merges streams of text", () => {
    let outputs = Immutable.List();

    outputs = reduceOutputs(outputs, {
      name: "stdout",
      text: "hello",
      output_type: "stream"
    });
    expect(
      Immutable.is(
        outputs,
        Immutable.fromJS([makeStreamOutput({ name: "stdout", text: "hello" })])
      )
    ).toBe(true);

    outputs = reduceOutputs(outputs, {
      name: "stdout",
      text: " world",
      output_type: "stream"
    });
    expect(
      Immutable.is(
        outputs,
        Immutable.fromJS([
          makeStreamOutput({ name: "stdout", text: "hello world" })
        ])
      )
    ).toBe(true);
  });
Exemple #2
0
  it('expresses value equality with set sequences', () => {
    var s1 = Set.of('A', 'B', 'C');
    expect(s1.equals(null)).toBe(false);

    var s2 = Set.of('C', 'B', 'A');
    expect(s1 === s2).toBe(false);
    expect(is(s1, s2)).toBe(true);
    expect(s1.equals(s2)).toBe(true);

    // Map and Set are not the same (keyed vs unkeyed)
    var v1 = Map({ A: 'A', C: 'C', B: 'B' });
    expect(is(s1, v1)).toBe(false);
  });
 it('surfaces NaN, null, and undefined', () => {
   expect(
     is(NaN, Seq.of(1, 2, 3, 4, 5, NaN).max())
   ).toBe(true);
   expect(
     is(NaN, Seq.of(NaN, 1, 2, 3, 4, 5).max())
   ).toBe(true);
   expect(
     is(null, Seq.of('A', 'B', 'C', 'D', null).max())
   ).toBe(true);
   expect(
     is(null, Seq.of(null, 'A', 'B', 'C', 'D').max())
   ).toBe(true);
 });
  test("appends output and tracks display IDs", () => {
    const originalState = monocellDocument;

    const id = originalState.getIn(["notebook", "cellOrder", 2]);

    const action = actions.appendOutput({
      id,
      output: {
        output_type: "display_data",
        data: { "text/html": "<marquee>wee</marquee>" },
        transient: { display_id: "1234" }
      }
    });

    const state = reducers(originalState, action);
    expect(state.getIn(["notebook", "cellMap", id, "outputs"])).toEqual(
      Immutable.fromJS([
        makeDisplayData({
          data: Immutable.Map({ "text/html": "<marquee>wee</marquee>" })
        })
      ])
    );

    expect(
      Immutable.is(
        state.getIn(["transient", "keyPathsForDisplays", "1234"]),
        Immutable.fromJS([["notebook", "cellMap", id, "outputs", 0]])
      )
    ).toBe(true);
  });
Exemple #5
0
 compare: function(actual, expected) {
   var passed = is(actual, expected);
   return {
     pass: passed,
     message: 'Expected ' + actual + (passed ? '' : ' not') + ' to equal ' + expected
   };
 }
Exemple #6
0
 it('should initialize a game state record with default values', () => {
   const choices = I.List([3, 4, 5]);
   const correctChoice = 4;
   const refreshChoices = spy(
     (game: TestState) => game.set('choices', choices)
   );
   const refreshCorrectChoice = spy(
     (game: TestState) => game.set('correctChoice', correctChoice)
   );
   const game = init(new TestStateRecord(), refreshChoices, refreshCorrectChoice);
   assert.strictEqual(refreshChoices.callCount, 1);
   assert.strictEqual(refreshCorrectChoice.callCount, 1);
   assert.strictEqual(game.level, 1);
   assert.strictEqual(game.step, 0);
   assert(I.is(game.choices, choices));
   assert.strictEqual(game.correctChoice, correctChoice);
   assert.strictEqual(game.lastGuess, null);
   assert.strictEqual(game.wasLastGuessCorrect, null);
   assert.strictEqual(game.presentCount, 0);
   assert.strictEqual(game.guessCount, 0);
   assert.strictEqual(game.guessCountForCurrentCorrectChoice, 0);
   assert.strictEqual(game.shouldRefreshChoices, false);
   assert.strictEqual(game.shouldRefreshCorrectChoice, false);
   assert.strictEqual(game.refreshChoicesCount, 1);
   assert.strictEqual(game.refreshCorrectChoiceCount, 1);
 });
 check.it('is not dependent on order', [genHeterogeneousishArray], vals => {
   expect(
     is(
       Seq(shuffle(vals.slice())).max(),
       Seq(vals).max()
     )
   ).toEqual(true);
 });
Exemple #8
0
 emit(value:any) {
   if (!refValues.has(this.key()) || !Immutable.is(refValues.get(this.key()), value)) {
     const listeners = refListeners.get(this.key());
     if (listeners) {
       refValues.set(this.key(), value);
       listeners.forEach(listener => listener(value));
     }
   }
 }
Exemple #9
0
 check.it('sets', {maxSize: 5000}, [gen.posInt], len => {
   var map = Map();
   for (var ii = 0; ii < len; ii++) {
     expect(map.size).toBe(ii);
     map = map.set(''+ii, ii);
   }
   expect(map.size).toBe(len);
   expect(is(map.toSet(), Range(0, len).toSet())).toBe(true);
 });
Exemple #10
0
 it('should refresh a game when forced', () => {
   const game = createAndInitGame();
   const newChoices = I.List([7, 8, 9]);
   const newCorrectChoice = 8;
   assert(!I.is(game.choices, newChoices));
   assert.notStrictEqual(game.correctChoice, newCorrectChoice);
   const updatedGame = refresh(
     game,
     (g: TestState) => g.set('choices', newChoices) as TestState,
     (g: TestState) => g.set('correctChoice', newCorrectChoice) as TestState,
     true
   );
   assert(I.is(updatedGame.choices, newChoices));
   assert.strictEqual(updatedGame.correctChoice, newCorrectChoice);
   assert.strictEqual(updatedGame.guessCountForCurrentCorrectChoice, 0);
   assert.strictEqual(game.refreshChoicesCount, updatedGame.refreshChoicesCount - 1);
   assert.strictEqual(game.refreshCorrectChoiceCount, updatedGame.refreshCorrectChoiceCount - 1);
 });