Question
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
private List
{
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("11/1/2017").Date
, DateTime.Parse("12/1/2017").Date}
, 1);
}
public bool createNewSchedule(int defaultNumberOfSlots
, bool isPublishable
, List
, int sectionId)
{
Schedule schedule = new Schedule();
schedule.defaultNumberOfSlots = defaultNumberOfSlots;
schedule.isPublishable = isPublishable;
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
, 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
// 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
{
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
{
Dictionary
if (sectionSchedule.ContainsKey(sectionId))
{
checkSchedule = sectionSchedule[sectionId].slotsByDate;
// remove used slots
foreach (List
{
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
List
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started