Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create TDD style functional black box test for getSlotNumbers() in the code below. Black Box Test: Arrange Act Assert using System; using System.Collections.Generic; namespace Schedule_App

Create TDD style functional black box test for getSlotNumbers() in the code below.

Black Box Test:

Arrange

Act

Assert

using System;

using System.Collections.Generic;

namespace Schedule_App

{

public class PresentationSchedule

{

private Dictionary sectionSchedule = new Dictionary();

private List makeSlots(int maxSlots)

{

List unusedMeetingSlots = new List();

for (int i = 1; i <= maxSlots; i++)

{

Slot slot = new Slot();

slot.slotNumber = i;

slot.isUsed = false;

unusedMeetingSlots.Add(slot);

}

return unusedMeetingSlots;

}

public PresentationSchedule()

{

// Make a mock schedule as seed data

createNewSchedule(4

, true

, new List() { DateTime.Parse("10/1/2017").Date

, DateTime.Parse("11/1/2017").Date

, DateTime.Parse("12/1/2017").Date}

, 1);

}

public bool createNewSchedule(int defaultNumberOfSlots

, bool isPublishable

, List meetingDates

, int sectionId)

{

Schedule schedule = new Schedule();

schedule.defaultNumberOfSlots = defaultNumberOfSlots;

schedule.isPublishable = isPublishable;

Dictionary> slotsByDate = new Dictionary>();

foreach (DateTime meetingDate in meetingDates)

{

slotsByDate.Add(meetingDate.Date, makeSlots(schedule.defaultNumberOfSlots));

}

schedule.slotsByDate = slotsByDate;

sectionSchedule.Add(sectionId, schedule);

return true;

}

public int getDefaultNumberOfSlots(int sectionId)

{

return sectionSchedule[sectionId].defaultNumberOfSlots;

}

public bool configurePresentationSchedule(int sectionId

, DateTime firstDate

, DateTime lastDate

, int numSlots

, List ExcludeDates

, bool isPublishable)

{

// Assume it will work unless a problem is encountered

bool isSuccessful = true;

if (sectionSchedule.ContainsKey(sectionId))

{

// There is already a schedule defined for this section

isSuccessful = false;

return isSuccessful;

}

if (lastDate.Date < firstDate.Date)

{

// illogical start and end dates

isSuccessful = false;

return isSuccessful;

}

const int MIN_NUMBER_OF_SLOTS = 1;

const int MAX_NUMBER_OF_SLOTS = 5;

if ((numSlots < MIN_NUMBER_OF_SLOTS) || (numSlots > MAX_NUMBER_OF_SLOTS))

{

// fails min or max presentation slots per class period

isSuccessful = false;

return isSuccessful;

}

if (firstDate.DayOfWeek != lastDate.DayOfWeek)

{

// classes must meet on the same day of the week

isSuccessful = false;

return isSuccessful;

}

// TBD: Need to check firstDate and LastDate against the academic year and semester

// generate a list of dates based on first and last date

List meetingDays = makeListOfMeetingDays(firstDate.Date, lastDate.Date);

// if there are excluded dates then remove them

if (ExcludeDates.Count > 0)

{

foreach (DateTime excludeDate in ExcludeDates)

{

meetingDays.RemoveAll(meetingDay => meetingDay.Date == excludeDate.Date);

//slotsByDate.Remove(excludeDate);

}

}

createNewSchedule(numSlots

, isPublishable

, meetingDays

, sectionId);

return isSuccessful;

}

private List makeListOfMeetingDays(DateTime firstDate, DateTime lastDate)

{

List listOfDates = new List();

listOfDates.Add(firstDate.Date);

DateTime dateMarker = firstDate.Date;

while (dateMarker.Date < lastDate.Date)

{

listOfDates.Add(dateMarker.AddDays(7));

dateMarker = dateMarker.AddDays(7).Date;

}

return listOfDates;

}

public Dictionary> getAvailableSlots(int sectionId)

{

Dictionary> checkSchedule;

if (sectionSchedule.ContainsKey(sectionId))

{

checkSchedule = sectionSchedule[sectionId].slotsByDate;

// remove used slots

foreach (List slots in checkSchedule.Values)

{

slots.RemoveAll(item => item.isUsed);

}

}

else

{

// return an empty list because the sectionId does not exist

checkSchedule = new Dictionary>();

}

return checkSchedule;

}

public bool selectSlot(int sectionId, int studentId, DateTime slotDate, int slotNum)

{

Dictionary> slotsByDate = sectionSchedule[sectionId].slotsByDate;

List slots = slotsByDate[slotDate.Date];

bool success = false;

foreach (Slot slot in slots)

{

if (slot.slotNumber == slotNum && !slot.isUsed)

{

success = true;

slot.isUsed = true;

slot.studentId = studentId;

}

}

return success;

}

public Schedule getScheduleBySection(int sectionId)

{

if (sectionSchedule.ContainsKey(sectionId))

{

return sectionSchedule[sectionId];

}

else

{

// no schedule exists for specified schedule

// so return an empty schedule

return new Schedule();

}

}

public int getSlotNumbers(int sectionId, DateTime meetingDate)

{

int numSlots = 0;

if (sectionSchedule.ContainsKey(sectionId))

{

if (sectionSchedule[sectionId].slotsByDate.ContainsKey(meetingDate.Date))

numSlots = sectionSchedule[sectionId].slotsByDate[meetingDate.Date].Count;

}

return numSlots;

}

public bool modifySlotNumbers(int sectionId, DateTime meetingDate, int numSlots)

{

List slots;

bool isSuccessful = false;

if (numSlots > 0)

{

if (sectionSchedule.ContainsKey(sectionId))

{

if (sectionSchedule[sectionId].slotsByDate.ContainsKey(meetingDate.Date))

{

slots = makeSlots(numSlots);

// remove the old key and value from the dictionary

sectionSchedule[sectionId].slotsByDate.Remove(meetingDate.Date);

// add the new key and value from the dictionary

sectionSchedule[sectionId].slotsByDate.Add(meetingDate.Date, slots);

// update the return value

isSuccessful = true;

}

}

}

return isSuccessful;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3 How supply and demand together determine market equilibrium.

Answered: 1 week ago