lantern

sprout-garden-phase-5-test

Test: Sprout Garden Phase 5

Following [[pattern-looking-glass-development]] - the tests ARE the documentation.

Subject

Phase 5 plot types: and-trellis, or-trellis, not-trellis, xor-trellis (boolean logic)

config

path: null
plots_dir: /Users/graemefawcett/working/ben.fawcett.family/activities/sprout-garden/src/plots/types

Spec

Test: AND Trellis Requires Both Inputs

describe('AND Trellis', () => {
  it('waits for both inputs before firing', () => {
    const and = andTrellis;
    and.receive({ shape: 'circle', color: 'red' }, 'A');
    
    expect(and.shouldFire()).toBe(false);
    
    and.receive({ shape: 'square', color: 'blue' }, 'B');
    
    expect(and.shouldFire()).toBe(true);
  });
  
  it('resets after firing', () => {
    const and = andTrellis;
    and.receive({ shape: 'circle', color: 'red' }, 'A');
    and.receive({ shape: 'square', color: 'blue' }, 'B');
    and.fire();
    
    expect(and.shouldFire()).toBe(false);
    expect(and.state.A).toBeNull();
    expect(and.state.B).toBeNull();
  });
  
  it('outputs first sprout by default', () => {
    const and = andTrellis;
    const sproutA = { shape: 'circle', color: 'red' };
    const sproutB = { shape: 'square', color: 'blue' };
    
    and.receive(sproutA, 'A');
    and.receive(sproutB, 'B');
    
    expect(and.fire()).toEqual(sproutA);
  });
});

Test: OR Trellis Passes Either Input

describe('OR Trellis', () => {
  it('fires immediately when A arrives', () => {
    const or = orTrellis;
    or.receive({ shape: 'circle', color: 'red' }, 'A');
    
    expect(or.shouldFire()).toBe(true);
  });
  
  it('fires immediately when B arrives', () => {
    const or = orTrellis;
    or.receive({ shape: 'square', color: 'blue' }, 'B');
    
    expect(or.shouldFire()).toBe(true);
  });
  
  it('passes through the arriving sprout', () => {
    const or = orTrellis;
    const sprout = { shape: 'circle', color: 'red' };
    or.receive(sprout, 'A');
    
    expect(or.fire()).toEqual(sprout);
  });
});

Test: NOT Trellis Inverts Properties

describe('NOT Trellis', () => {
  it('inverts circle to star', () => {
    const not = createNotTrellis({ invert: 'shape' });
    const sprout = { shape: 'circle', color: 'red' };
    
    expect(not.grow(sprout).shape).toBe('star');
    expect(not.grow(sprout).color).toBe('red'); // unchanged
  });
  
  it('inverts star to circle', () => {
    const not = createNotTrellis({ invert: 'shape' });
    const sprout = { shape: 'star', color: 'blue' };
    
    expect(not.grow(sprout).shape).toBe('circle');
  });
  
  it('inverts square to triangle', () => {
    const not = createNotTrellis({ invert: 'shape' });
    expect(not.grow({ shape: 'square', color: 'red' }).shape).toBe('triangle');
  });
  
  it('inverts triangle to square', () => {
    const not = createNotTrellis({ invert: 'shape' });
    expect(not.grow({ shape: 'triangle', color: 'red' }).shape).toBe('square');
  });
  
  it('inverts red to blue', () => {
    const not = createNotTrellis({ invert: 'color' });
    expect(not.grow({ shape: 'circle', color: 'red' }).color).toBe('blue');
  });
  
  it('inverts green to yellow', () => {
    const not = createNotTrellis({ invert: 'color' });
    expect(not.grow({ shape: 'circle', color: 'green' }).color).toBe('yellow');
  });
  
  it('can invert both properties', () => {
    const not = createNotTrellis({ invert: 'both' });
    const sprout = { shape: 'circle', color: 'red' };
    const result = not.grow(sprout);
    
    expect(result.shape).toBe('star');
    expect(result.color).toBe('blue');
  });
});

Test: XOR Trellis Exclusive Logic

describe('XOR Trellis', () => {
  it('fires when only A arrives', () => {
    const xor = xorTrellis;
    xor.receive({ shape: 'circle', color: 'red' }, 'A');
    xor.tick(); // Process at end of tick
    
    expect(xor.shouldFire()).toBe(true);
  });
  
  it('fires when only B arrives', () => {
    const xor = xorTrellis;
    xor.receive({ shape: 'square', color: 'blue' }, 'B');
    xor.tick();
    
    expect(xor.shouldFire()).toBe(true);
  });
  
  it('does NOT fire when both arrive same tick', () => {
    const xor = xorTrellis;
    xor.receive({ shape: 'circle', color: 'red' }, 'A');
    xor.receive({ shape: 'square', color: 'blue' }, 'B');
    xor.tick();
    
    expect(xor.shouldFire()).toBe(false);
  });
});

Test: Logic Gate Integration

describe('Logic Gate Integration', () => {
  it('can build NAND from AND + NOT', () => {
    // NAND = NOT(AND(A, B))
    const sim = new Simulation(nandCircuitGarden);
    sim.run();
    
    // Truth table verification
    // A=0, B=0 → 1
    // A=0, B=1 → 1  
    // A=1, B=0 → 1
    // A=1, B=1 → 0
  });
  
  it('synchronizes multiple sprout streams', () => {
    const sim = new Simulation(syncGarden);
    sim.run();
    
    // All sprouts should exit AND gate together
    const arrivals = sim.sprouts
      .filter(s => s.status === 'arrived')
      .map(s => s.lineage.at(-1).tick);
    
    // All arrived same tick
    expect(new Set(arrivals).size).toBe(1);
  });
});

Results

{
  "summary": "0/5 tests passing",
  "phase": "Phase 5: Logic Trellises",
  "status": "not yet implemented",
  "tests": [
    {
      "test": "and-trellis.js exists",
      "status": "fail",
      "details": "not yet implemented"
    },
    {
      "test": "or-trellis.js exists",
      "status": "fail",
      "details": "not yet implemented"
    },
    {
      "test": "not-trellis.js exists",
      "status": "fail",
      "details": "not yet implemented"
    },
    {
      "test": "xor-trellis.js exists",
      "status": "fail",
      "details": "not yet implemented"
    },
    {
      "test": "nand-trellis.js exists",
      "status": "fail",
      "details": "not yet implemented"
    }
  ]
}

Provenance

Fences

test-and-trellis

  • Status: Spec only (Phase 5 not implemented)
  • By: Claude (2025-11-29)
  • Note: AND gate behavior

test-or-trellis

  • Status: Spec only
  • By: Claude (2025-11-29)
  • Note: OR gate behavior

test-not-trellis

  • Status: Spec only
  • By: Claude (2025-11-29)
  • Note: Property inversion

test-xor-trellis

  • Status: Spec only
  • By: Claude (2025-11-29)
  • Note: Exclusive or behavior

test-logic-integration

  • Status: Spec only
  • By: Claude (2025-11-29)
  • Note: Building complex gates from simple ones

sprout-garden-phase-5-results

  • Status: Verified (checks for implementation)
  • By: Claude (2025-11-29)
  • Note: Reports Phase 5 implementation status

Slots

North

slots:
- sprout-garden-phase-5

South

slots: []

East

slots: []

West

slots:
- pattern-looking-glass-development