jasonmzx / Software-Quality-Final-Project

Software Quality 3980U
1 stars 0 forks source link

Build & Test the Flight Network Objects using TDD approach #1

Closed jasonmzx closed 7 months ago

jasonmzx commented 7 months ago

I'd suggest Red / Green / Refactor for this, as you'll be either writing algorithms to generate the flights, or maybe just hard-code them like I've been doing, and it will be prone to error!

SOFE3980U_Final_Project/src/main/java/com/ontariotechu/sofe3980U/core/MemoryStore.java

MemoryStore.java, In Constructor lines 36-76

        // ... ^^
        //EU Airports:

        airportsList.add(new Airport("HAM - Hamburg Airport", "Europe/Berlin", 21)); //hamburg | germany
        airportsList.add(new Airport("FRA - Frankfurt Airport", "Europe/Berlin", 11));
        airportsList.add(new Airport("MUC - Munich Airport", "Europe/Berlin", 22));
        airportsList.add(new Airport("CDG - Charles de Gaulle Airport", "Europe/Paris", 12)); //paris | france
        airportsList.add(new Airport("PRG - Vaclav Havel Airport Prague", "Europe/Prague", 13)); //prague | czech
        airportsList.add(new Airport("BRQ - Brno-Turany Airport", "Europe/Prague", 24)); //brno | czech
        airportsList.add(new Airport("BTS - Bratislava Airport", "Europe/Bratislava", 20)); //bratislava | slovakia
        airportsList.add(new Airport("ZAG - Zagreb Airport", "Europe/Zagreb", 23)); //zagreb | croatia
        airportsList.add(new Airport("VIE - Vienna International Airport", "Europe/Vienna", 17)); // vienna | austria
        airportsList.add(new Airport("ZRH - Zurich Airport", "Europe/Zurich", 14));
        airportsList.add(new Airport("LHR - Heathrow Airport", "Europe/London", 4));
        airportsList.add(new Airport("EDI - Edinburgh Airport", "Europe/London", 19));

        // Other:

        airportsList.add(new Airport("MRU - Sr. Seewoosagur Ramgoolam International Airport", "Indian/Mauritius", 16));
        airportsList.add(new Airport("SYD - Sydney Airport", "Australia/Sydney", 7));

        // Build some Flight paths (Flight Network)

        LocalTime time1530 = LocalTime.of(15, 30);
        LocalTime time1730 = LocalTime.of(17, 30);

        LocalTime time0615 = LocalTime.of(6, 15);
        LocalTime time0930 = LocalTime.of(9, 30);

        DowDate departDate = new DowDate(0,time1530);
        DowDate arrivalDate= new DowDate(0, time1730);

        flightNetworkList.add(new Flight(airportsList.get(5), airportsList.get(1), departDate,arrivalDate));

        DowDate departDate2 = new DowDate(0,time0615);
        DowDate arrivalDate2= new DowDate(0, time0930);

        flightNetworkList.add(new Flight(airportsList.get(5), airportsList.get(2), departDate,arrivalDate));

//...

Above is where the implementation should go, it's up to you to make other helper files, Remember SINGLE RESPONSIBILITY PRINCIPLE is always a bonus!

Preform testing in this file:

SOFE3980U_Final_Project/src/test/java/com/ontariotechu/sofe3980U/core/MemoryStoreTest.java

package com.ontariotechu.sofe3980U.core;

// Core Imports

import com.ontariotechu.sofe3980U.core.MemoryStore;

// std imports

import java.util.List;
import java.util.Set;
import java.util.HashSet;

// JUnit Imports

import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.test.annotation.Repeat;

public class MemoryStoreTest {

    //Airport Tests (Data Integrity Tests)

    @Test
    public void testUniqueAirportIDs() {
        List<Airport> airports = MemoryStore.getInstance().getAirportList();
        assertNotNull(airports);
        assertFalse(airports.isEmpty());

        Set<Integer> ids = new HashSet<>();
        for (Airport airport : airports) {
            assertFalse(ids.contains(airport.getID()));
            ids.add(airport.getID());
        }
    }

    //Flight Network Tests (Data Integrity Tests)

    //TODO

}

This task should be done PRIOR to building the actual Flight Traversal algorithm from Point A to Point B !