|
9 | 9 | reverseConnection,
|
10 | 10 | onFloor,
|
11 | 11 | } from ".";
|
12 |
| -import { isValidBuilding } from "./buildingValidity"; |
| 12 | +import { assertValidBuilding, isValidBuilding } from "./buildingValidity"; |
13 | 13 |
|
14 | 14 | const { RIGHT, LEFT, FRONT } = Direction;
|
15 | 15 |
|
@@ -533,10 +533,166 @@ describe("accessibility", () => {
|
533 | 533 | expect.objectContaining({
|
534 | 534 | valid: false,
|
535 | 535 | reason:
|
536 |
| - "The hallway at index 4 has no nodes (Forks or Stairs) to connect it to the rest of the building.", |
| 536 | + "The hallway at index 4 has no connector nodes (Forks or Stairs) to connect it to the rest of the building.", |
537 | 537 | })
|
538 | 538 | );
|
539 | 539 | });
|
540 | 540 | });
|
541 | 541 |
|
| 542 | +describe("one-way hallways", () => { |
| 543 | + const hallway10 = [ |
| 544 | + new Stairs(RIGHT, onFloor("b", 1)), |
| 545 | + new Room("101"), |
| 546 | + new Room("102"), |
| 547 | + new Room("103"), |
| 548 | + new Fork(RIGHT, "a", "the 11s"), |
| 549 | + ]; |
| 550 | + const hallway11 = [ |
| 551 | + new Fork(FRONT, reverseConnection("a"), "the 10s"), |
| 552 | + new Room("111"), |
| 553 | + new Room("112"), |
| 554 | + new Room("113"), |
| 555 | + new Stairs(RIGHT, onFloor("c", 1)), |
| 556 | + ]; |
| 557 | + |
| 558 | + const hallway20 = [ |
| 559 | + new Stairs(RIGHT, onFloor("b", 2)), |
| 560 | + new Room("201"), |
| 561 | + new Room("202"), |
| 562 | + new Room("203"), |
| 563 | + new Fork(RIGHT, "e", "the 11s"), |
| 564 | + ]; |
| 565 | + const hallway21 = [ |
| 566 | + new Fork(FRONT, reverseConnection("e"), "the 11s"), |
| 567 | + new Room("211"), |
| 568 | + new Room("212"), |
| 569 | + new Room("213"), |
| 570 | + new Stairs(RIGHT, onFloor("c", 2)), |
| 571 | + ]; |
| 572 | + |
| 573 | + let controlAnswer: string | null; |
| 574 | + |
| 575 | + test("control case", () => { |
| 576 | + const building = new Building([ |
| 577 | + new Hallway(hallway10), |
| 578 | + new Hallway(hallway11), |
| 579 | + new Hallway(hallway20), |
| 580 | + new Hallway(hallway21), |
| 581 | + ]); |
| 582 | + assertValidBuilding(building); |
| 583 | + |
| 584 | + controlAnswer = building.getDirections("103", "111"); |
| 585 | + |
| 586 | + expect(controlAnswer).toMatchInlineSnapshot(` |
| 587 | + "Turn left out of room 103 |
| 588 | + Continue, then turn right into the 11s |
| 589 | + Continue, then turn left into room 111" |
| 590 | + `); |
| 591 | + }); |
| 592 | + |
| 593 | + test("one-way hallway with same directions", () => { |
| 594 | + const building = new Building([ |
| 595 | + new Hallway(hallway10, { oneWay: "forward" }), |
| 596 | + new Hallway(hallway11, { oneWay: "forward" }), |
| 597 | + new Hallway(hallway20), |
| 598 | + new Hallway(hallway21), |
| 599 | + ]); |
| 600 | + assertValidBuilding(building); |
| 601 | + |
| 602 | + expect(building.getDirections("103", "111")).toBe(controlAnswer); |
| 603 | + }); |
| 604 | + |
| 605 | + test("one-way hallway 1", () => { |
| 606 | + const building = new Building([ |
| 607 | + new Hallway(hallway10, { oneWay: "backward" }), |
| 608 | + new Hallway(hallway11, { oneWay: "backward" }), |
| 609 | + new Hallway(hallway20), |
| 610 | + new Hallway(hallway21), |
| 611 | + ]); |
| 612 | + assertValidBuilding(building); |
| 613 | + |
| 614 | + expect(building.getDirections("103", "111")).not.toBe(controlAnswer); |
| 615 | + |
| 616 | + expect(building.getDirections("103", "111")).toMatchInlineSnapshot(` |
| 617 | + "Turn right out of room 103 |
| 618 | + Continue, then turn left into the stairs |
| 619 | + Go up 1 floor of stairs |
| 620 | + Turn right out of the stairs |
| 621 | + Continue, then turn right into the 11s |
| 622 | + Continue, then turn right into the stairs |
| 623 | + Go down 1 floor of stairs |
| 624 | + Turn left out of the stairs |
| 625 | + Continue, then turn right into room 111" |
| 626 | + `); |
| 627 | + }); |
| 628 | + |
| 629 | + test("one-way hallway 2", () => { |
| 630 | + const building = new Building([ |
| 631 | + new Hallway(hallway10, { oneWay: "backward" }), |
| 632 | + new Hallway(hallway11), |
| 633 | + new Hallway(hallway20), |
| 634 | + new Hallway(hallway21), |
| 635 | + ]); |
| 636 | + assertValidBuilding(building); |
| 637 | + |
| 638 | + expect(building.getDirections("103", "111")).not.toBe(controlAnswer); |
| 639 | + |
| 640 | + expect(building.getDirections("103", "111")).toMatchInlineSnapshot(` |
| 641 | + "Turn right out of room 103 |
| 642 | + Continue, then turn left into the stairs |
| 643 | + Go up 1 floor of stairs |
| 644 | + Turn right out of the stairs |
| 645 | + Continue, then turn right into the 11s |
| 646 | + Continue, then turn right into the stairs |
| 647 | + Go down 1 floor of stairs |
| 648 | + Turn left out of the stairs |
| 649 | + Continue, then turn right into room 111" |
| 650 | + `); |
| 651 | + }); |
| 652 | + |
| 653 | + test("one-way hallway 3", () => { |
| 654 | + const building = new Building([ |
| 655 | + new Hallway(hallway10, { oneWay: "backward" }), |
| 656 | + new Hallway(hallway11), |
| 657 | + new Hallway(hallway20), |
| 658 | + new Hallway(hallway21), |
| 659 | + ]); |
| 660 | + assertValidBuilding(building); |
| 661 | + |
| 662 | + expect(building.getDirections("101", "103")).toMatchInlineSnapshot(` |
| 663 | + "Turn right out of room 101 |
| 664 | + Continue, then turn left into the stairs |
| 665 | + Go up 1 floor of stairs |
| 666 | + Turn right out of the stairs |
| 667 | + Continue, then turn right into the 11s |
| 668 | + Continue, then turn right into the stairs |
| 669 | + Go down 1 floor of stairs |
| 670 | + Turn left out of the stairs |
| 671 | + Continue, then after entering the 10s, turn left |
| 672 | + Continue, then turn right into room 103" |
| 673 | + `); |
| 674 | + }); |
| 675 | + |
| 676 | + test("unconnected one-way building 1", () => { |
| 677 | + const building = new Building([ |
| 678 | + new Hallway(hallway10, { oneWay: "backward" }), |
| 679 | + new Hallway(hallway11, { oneWay: "forward" }), |
| 680 | + new Hallway(hallway20), |
| 681 | + new Hallway(hallway21), |
| 682 | + ]); |
| 683 | + expect(isValidBuilding(building).valid).toBe(false); |
| 684 | + }); |
| 685 | + test("unconnected one-way building 2", () => { |
| 686 | + const building = new Building([ |
| 687 | + new Hallway(hallway10, { oneWay: "forward" }), |
| 688 | + new Hallway(hallway11, { oneWay: "backward" }), |
| 689 | + new Hallway(hallway20), |
| 690 | + new Hallway(hallway21), |
| 691 | + ]); |
| 692 | + expect(isValidBuilding(building).valid).toBe(false); |
| 693 | + }); |
| 694 | +}); |
| 695 | + |
| 696 | +// describe("one-way connections", () => {}); |
| 697 | + |
542 | 698 | // TODO: add tests with SimpleHallway and rooms that are nodes
|
0 commit comments