public async Task Offer_adjacent_3_seats_nearer_the_middle_of_a_row_when_it_is_possible() { var showId = new ShowId("3"); var partyRequested = new PartyRequested(3); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)) .ContainsExactly("A6-A7-A8"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Second)) .ContainsExactly("C4-C5-C6", "C1-C2-C3", "C7-C8-C9"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Third)); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Third)) .ContainsExactly("E4-E5-E6", "E1-E2-E3", "E7-E8-E9"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Mixed)) .ContainsExactly("A6-A7-A8", "B2-B3-B4", "C4-C5-C6"); }
private void confirmBookingButton_Click(object sender, EventArgs e) { int bookingAmount = int.Parse(bookingAmountTextbox.Text); int seatsRemaining = c.Capacity - j.getSeatsTaken(operation); if (bookingAmount > 0) { if (bookingAmount < seatsRemaining) { Customer user = (Customer)Session["user"]; Booking booking = new Booking(user.Id, j.Id, operation, bookingAmount); if (booking.insertToDb()) { SeatAllocator.allocateSeats(Booking.getBookingsByJourneyIDAndDateAsList(j.Id, operation), c); HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=\"\"JavaScript\"\">alert(\"Booking successful! You will now be redirected.\")</SCRIPT>"); HttpContext.Current.Response.Redirect("../customer/RouteListing.aspx"); } else { HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=\"\"JavaScript\"\">alert(\"Booking failed. Please try again.\")</SCRIPT>"); } } else { HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=\"\"JavaScript\"\">alert(\"Only " + seatsRemaining + " are remaining. Please enter a lower number.\")</SCRIPT>"); } } else { HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=\"\"JavaScript\"\">alert(\"Please enter a number higher than zero.\")</SCRIPT>"); } }
public void getSeatId(string seatSpec, int expected) { SeatAllocator allocator = new SeatAllocator(); int column = allocator.GetSeatId(seatSpec); Assert.That(column, Is.EqualTo(expected)); }
public void findColumn() { SeatAllocator allocator = new SeatAllocator(); int column = allocator.FindColumn("RLR"); Assert.That(column, Is.EqualTo(5)); }
public void findRow() { SeatAllocator allocator = new SeatAllocator(); int row = allocator.FindRow("FBFBBFF"); Assert.That(row, Is.EqualTo(44)); }
public async Task <ActionResult <SuggestionsMade> > MakeSuggestion([FromQuery(Name = "showId")] string showId, [FromQuery(Name = "party")] int party) { var seatAllocator = new SeatAllocator(new AuditoriumSeatingAdapter(_auditoriumSeatingRepository, _seatReservationsProvider)); var suggestions = await seatAllocator.MakeSuggestions(new ShowId(showId), new PartyRequested(party)); return(suggestions); }
public async Task Offer_adjacent_seats_nearer_the_middle_of_a_row() { var showId = new ShowId("9"); var partyRequested = new PartyRequested(1); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)).ContainsExactly("A4", "A3", "B5"); }
public async Task Suggest_one_seat_when_Auditorium_contains_one_available_seat_only() { var showId = new ShowId("1"); var partyRequested = new PartyRequested(1); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)).ContainsExactly("A3"); }
/// <summary> /// Build and return a full hexagon + its adapters, stubbing only the last-miles HTTP calls. /// </summary> /// <returns></returns> public SeatsSuggestionsController BuildImperativeShellWithAdaptersButWithoutIOs() { // Instantiate the Right-side adapter var rightSideAdapter = InstantiateRightSideAdapter(_showId, _theaterJson, _theaterBookedSeatsJson); // create impure imperative shell by partially applying the provide function in the core. SeatAllocator.SuggestionsDelegate suggestionsDelegate = (id, party) => SeatAllocator.MakeSuggestionsImperativeShell(rightSideAdapter, id, party); // Instantiate the Left-side adapter var leftSideAdapter = new SeatsSuggestionsController(suggestionsDelegate); // Balance restored : Underlying hexagon (essentially the 'main' module) knows how to assemble adapters to core but nothing else // Note: // - iso injecting the functions into the controller and rightside adapters, these could also be injected by creting more partially applied functions YMMV return(leftSideAdapter); }
static void Main(string[] args) { List <string> input = new List <string>(); using (FileStream stream = new FileStream("InputFile.txt", FileMode.Open)) { using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { input.Add(reader.ReadLine()); } } } List <int> seatIds = new List <int>(); SeatAllocator allocator = new SeatAllocator(); foreach (string seatSpec in input) { seatIds.Add(allocator.GetSeatId(seatSpec)); } // Part 1 //Console.WriteLine(seatIds.Max()); seatIds = seatIds.OrderBy(i => i).ToList(); //foreach(int seatId in seatIds) //{ // Console.WriteLine(seatId); //} for (int i = seatIds.Min(); i < seatIds.Max(); i++) { if (!seatIds.Contains(i) && seatIds.Contains(i - 1) && seatIds.Contains(i + 1)) { Console.WriteLine(i); } } Console.ReadLine(); }
public async Task <IActionResult> GetSuggestionsFor([FromQuery(Name = "showId")] string showId, [FromQuery(Name = "party")] int party) { // Imperative shell for this use case ------------------------------- // Infra => Domain var id = new ShowId(showId); var partyRequested = new PartyRequested(party); // non-pure function var auditoriumSeating = await _auditoriumSeatingProvider.GetAuditoriumSeating(id); // pure function (the core) var suggestions = SeatAllocator .TryMakeSuggestions(id, partyRequested, auditoriumSeating) .GetValueOrFallback(new SuggestionNotAvailable(id, partyRequested)); // Domain => Infra return(new OkObjectResult(suggestions /*JsonConvert.SerializeObject(suggestions, Formatting.Indented)*/)); }
public async Task Return_SeatsNotAvailable_when_Auditorium_has_all_its_seats_already_reserved() { var showId = new ShowId("5"); var partyRequested = new PartyRequested(1); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.PartyRequested).IsEqualTo(partyRequested); Check.That(suggestionsMade.ShowId).IsEqualTo(showId); Check.That(suggestionsMade).IsInstanceOf <SuggestionNotAvailable>(); }
public void AllocateSeat1Party() { //Arrange var stubParty = new FakeStandingParty(); stubParty.Votes = 0; var partyList = new List <StandingParty>(); partyList.Add(stubParty); var allocator = new SeatAllocator(partyList); //Act allocator.AllocateSeat(); var actual = stubParty.Seats; //Assert Assert.Equal(1, actual); }
public async Task Offer_several_suggestions_ie_1_per_PricingCategory_and_other_one_without_category_affinity() { var showId = new ShowId("18"); var partyRequested = new PartyRequested(1); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)).ContainsExactly("A5", "A6", "A4"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Second)).ContainsExactly("A2", "A9", "A1"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Third)).ContainsExactly("E5", "E6", "E4"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Mixed)).ContainsExactly("A5", "A6", "A4"); }
private void btnReallocateSeats_Click(object sender, EventArgs e) { List <Booking> bookings = Booking.getBookingsByJourneyIDAndDateAsList(journeyID, date); Journey j = Journey.getJourneyByID(journeyID); Coach c = Coach.getCoachByID(j.CoachID); SeatAllocator.allocateSeats(bookings, c); StringBuilder str = new StringBuilder(); foreach (Booking b in bookings) { str.Append(b.BookingID.ToString() + ": "); foreach (String s in b.AllocatedSeats) { str.Append(s + " "); } str.Append("\n"); } refreshData(); MessageBox.Show("Seats reallocated"); }
public async Task Offer_4_adjacent_seats_nearer_the_middle_of_a_row_when_it_is_possible() { var showId = new ShowId("3"); var partyRequested = new PartyRequested(4); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)).IsEmpty(); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Second)) .ContainsExactly("C4-C5-C6-C7", "D4-D5-D6-D7"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Third)) .ContainsExactly("E4-E5-E6-E7", "F4-F5-F6-F7"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Mixed)) .ContainsExactly("A6-A7-A8-A9", "B1-B2-B3-B4", "C4-C5-C6-C7"); }
public void AllocateSeat2PartiesLosersSeats() { //Arrange var stubPartyWinner = new FakeStandingParty(); stubPartyWinner.Votes = 1; var stubPartyLoser = new FakeStandingParty(); stubPartyLoser.Votes = 0; var partyList = new List <StandingParty>(); partyList.Add(stubPartyWinner); partyList.Add(stubPartyLoser); var allocator = new SeatAllocator(partyList); //Act allocator.AllocateSeat(); var actual = stubPartyLoser.Seats; //Assert Assert.Equal(0, actual); }