Skip to content

Instantly share code, notes, and snippets.

@bobthemighty
Created September 30, 2021 14:15
Show Gist options
  • Save bobthemighty/ed804d9f1bd76c038748fe829b668bae to your computer and use it in GitHub Desktop.
Save bobthemighty/ed804d9f1bd76c038748fe829b668bae to your computer and use it in GitHub Desktop.
ponicode
import { Station, bill } from "../lib";
describe("A single journey in zone A", () => {
const taps: Array<Station> = [Station.Asterisk, Station.Aldgate];
it("should charge £2.50 for the journey", () => {
const [charge] = bill(taps);
expect(charge.amount).toEqual(250);
});
});
describe("One-Way Zone 1 to Zone 2 Journey", () => {
const taps: Array<Station> = [Station.Asterisk, Station.Barbican];
it("should charge £3.00 for the journey", () => {
const [charge] = bill(taps);
expect(charge.amount).toEqual(300);
});
});
describe("Multiple journeys", () => {
const taps: Array<Station> = [
Station.Asterisk,
Station.Aldgate,
Station.Asterisk,
Station.Balham,
];
const charges = Array.from(bill(taps));
it("should issue two charges", () => {
expect(charges).toHaveLength(2);
});
});
describe("Multiple journeys including zone B reaching daily cap", () => {
const taps: Array<Station> = [
Station.Asterisk,
Station.Barbican,
Station.Barbican,
Station.Balham,
Station.Balham,
Station.Bison,
Station.Bison,
Station.Asterisk,
];
const charges = Array.from(bill(taps));
it("should charge 2.00 for his third journey", () => {
expect(charges[2].amount).toEqual(200);
});
});
describe("Multiple journeys in zone A reaching daily cap", () => {
const taps: Array<Station> = [
Station.Asterisk,
Station.Aldgate,
Station.Aldgate,
Station.Angel,
Station.Angel,
Station.Antelope,
Station.Antelope,
Station.Asterisk,
];
const charges = Array.from(bill(taps));
it("should charge 2.00 for his third journey", () => {
expect(charges[2].amount).toEqual(200);
});
});
describe("When a journey starts in zone B and ends in zone A", () => {
const taps = [Station.Bison, Station.Aldgate];
it("should charge 3.00", () => {
const [charge] = bill(taps);
expect(charge.amount).toEqual(300);
});
});
describe("Multiple return journeys", () => {
const taps = [
Station.Asterisk,
Station.Barbican,
Station.Barbican,
Station.Asterisk,
Station.Asterisk,
Station.Balham,
Station.Balham,
Station.Asterisk,
];
const charges = Array.from(bill(taps));
it("should charge 2.50 for the second journey", () => {
const [_, charge] = charges;
expect(charge.amount).toEqual(250);
});
});
describe("Two separate journeys, returning to the same point", () => {
const taps = [
Station.Asterisk,
Station.Balham,
Station.Barbican,
Station.Asterisk,
];
it("should not charge a return fare for the second journey", () => {
const [_, charge] = bill(taps);
expect(charge.amount).toEqual(300);
});
});
import * as gilded_rose from "./gilded-rose"
// @ponicode
describe("updateQuality", () => {
let inst: any
beforeEach(() => {
inst = new gilded_rose.GildedRose(32)
})
test("0", () => {
let callFunction: any = () => {
inst.updateQuality()
}
expect(callFunction).not.toThrow()
})
})
import rewire from "rewire"
const index = rewire("./index")
const zoneFor = index.__get__("zoneFor")
const isZoneB = index.__get__("isZoneB")
const isReturn = index.__get__("isReturn")
const priceFor = index.__get__("priceFor")
// @ponicode
describe("zoneFor", () => {
test("0", () => {
let callFunction: any = () => {
zoneFor(index.Station.Aldgate)
}
expect(callFunction).not.toThrow()
})
test("1", () => {
let callFunction: any = () => {
zoneFor(index.Station.Antelope)
}
expect(callFunction).not.toThrow()
})
test("2", () => {
let callFunction: any = () => {
zoneFor(index.Station.Barbican)
}
expect(callFunction).not.toThrow()
})
test("3", () => {
let callFunction: any = () => {
zoneFor(index.Station.Balham)
}
expect(callFunction).not.toThrow()
})
test("4", () => {
let callFunction: any = () => {
zoneFor(index.Station.Bison)
}
expect(callFunction).not.toThrow()
})
})
// @ponicode
describe("isZoneB", () => {
test("0", () => {
let callFunction: any = () => {
isZoneB({ origin: index.Station.Antelope, destination: index.Station.Bison })
}
expect(callFunction).not.toThrow()
})
test("1", () => {
let callFunction: any = () => {
isZoneB({ origin: index.Station.Antelope, destination: index.Station.Aldgate })
}
expect(callFunction).not.toThrow()
})
test("2", () => {
let callFunction: any = () => {
isZoneB({ origin: index.Station.Barbican, destination: index.Station.Asterisk })
}
expect(callFunction).not.toThrow()
})
test("3", () => {
let callFunction: any = () => {
isZoneB({ origin: index.Station.Angel, destination: index.Station.Bison })
}
expect(callFunction).not.toThrow()
})
test("4", () => {
let callFunction: any = () => {
isZoneB({ origin: index.Station.Bison, destination: index.Station.Antelope })
}
expect(callFunction).not.toThrow()
})
})
// @ponicode
describe("isReturn", () => {
test("0", () => {
let callFunction: any = () => {
isReturn({ total: 0.0, cap: "bc23a9d531064583ace8f67dad60f6bb", previousJourney: { origin: index.Station.Antelope, destination: index.Station.Aldgate } }, { origin: index.Station.Antelope, destination: index.Station.Balham })
}
expect(callFunction).not.toThrow()
})
test("1", () => {
let callFunction: any = () => {
isReturn({ total: 0.0, cap: 12345, previousJourney: { origin: index.Station.Antelope, destination: index.Station.Aldgate } }, { origin: index.Station.Antelope, destination: index.Station.Balham })
}
expect(callFunction).not.toThrow()
})
test("2", () => {
let callFunction: any = () => {
isReturn({ total: 300, cap: "bc23a9d531064583ace8f67dad60f6bb", previousJourney: { origin: index.Station.Antelope, destination: index.Station.Aldgate } }, { origin: index.Station.Antelope, destination: index.Station.Balham })
}
expect(callFunction).not.toThrow()
})
test("3", () => {
let callFunction: any = () => {
isReturn({ total: 10000, cap: 56784, previousJourney: { origin: index.Station.Antelope, destination: index.Station.Aldgate } }, { origin: index.Station.Asterisk, destination: index.Station.Aldgate })
}
expect(callFunction).not.toThrow()
})
test("4", () => {
let callFunction: any = () => {
isReturn({ total: 300, cap: 987650, previousJourney: { origin: index.Station.Barbican, destination: index.Station.Balham } }, { origin: index.Station.Balham, destination: index.Station.Antelope })
}
expect(callFunction).not.toThrow()
})
test("5", () => {
let callFunction: any = () => {
isReturn({ total: NaN, cap: NaN, previousJourney: { origin: index.Station.Asterisk, destination: index.Station.Angel } }, { origin: index.Station.Balham, destination: index.Station.Barbican })
}
expect(callFunction).not.toThrow()
})
})
// @ponicode
describe("priceFor", () => {
test("0", () => {
let callFunction: any = () => {
priceFor({ total: 6.0, cap: 12, previousJourney: { origin: index.Station.Aldgate, destination: index.Station.Balham } }, { origin: index.Station.Bison, destination: index.Station.Asterisk })
}
expect(callFunction).not.toThrow()
})
test("1", () => {
let callFunction: any = () => {
priceFor({ total: 0, cap: 12345, previousJourney: { origin: index.Station.Aldgate, destination: index.Station.Balham } }, { origin: index.Station.Asterisk, destination: index.Station.Balham })
}
expect(callFunction).not.toThrow()
})
test("2", () => {
let callFunction: any = () => {
priceFor({ total: 300, cap: 56784, previousJourney: { origin: index.Station.Aldgate, destination: index.Station.Balham } }, { origin: index.Station.Balham, destination: index.Station.Angel })
}
expect(callFunction).not.toThrow()
})
test("3", () => {
let callFunction: any = () => {
priceFor({ total: 0, cap: 12, previousJourney: { origin: index.Station.Aldgate, destination: index.Station.Balham } }, { origin: index.Station.Bison, destination: index.Station.Asterisk })
}
expect(callFunction).not.toThrow()
})
test("4", () => {
let callFunction: any = () => {
priceFor({ total: 0.0, cap: 56784, previousJourney: { origin: index.Station.Aldgate, destination: index.Station.Balham } }, { origin: index.Station.Balham, destination: index.Station.Angel })
}
expect(callFunction).not.toThrow()
})
test("5", () => {
let callFunction: any = () => {
priceFor({ total: Infinity, cap: Infinity, previousJourney: { origin: index.Station.Aldgate, destination: index.Station.Balham } }, { origin: index.Station.Bison, destination: index.Station.Asterisk })
}
expect(callFunction).not.toThrow()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment