random-flight-generator
Version:
A tool for generating random flights.
85 lines (84 loc) • 3.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var AirportUtils_1 = require("../AirportUtils");
var Flight_1 = require("../Flight");
var FlightGenerator_1 = require("../FlightGenerator");
var flightGenerator;
describe('generateFlight', function () {
describe('when given both departure and arrival', function () {
it('should return two non-random generated flights', function () {
flightGenerator = new FlightGenerator_1.FlightGenerator({
departure: '92VA',
arrival: 'KMIA',
});
var flight = flightGenerator.generateFlight();
expect(flight.departure.randomlyGenerated).toBe(false);
expect(flight.arrival.randomlyGenerated).toBe(false);
});
});
describe('when given a departure', function () {
it('should return a random arrival', function () {
flightGenerator = new FlightGenerator_1.FlightGenerator({
departure: 'KMIA',
minDistance: 15,
maxDistance: 200,
excludeCountries: ['AU', 'CA'],
});
var flight = flightGenerator.generateFlight();
expect(flight.departure.randomlyGenerated).toBe(false);
expect(flight.arrival.randomlyGenerated).toBe(true);
});
});
describe('when given an arrival', function () {
it('should return a random departure', function () {
flightGenerator = new FlightGenerator_1.FlightGenerator({
arrival: 'KMIA',
minDistance: 15,
maxDistance: 200,
excludeCountries: ['AU', 'CA'],
});
var flight = flightGenerator.generateFlight();
expect(flight.departure.randomlyGenerated).toBe(true);
expect(flight.arrival.randomlyGenerated).toBe(false);
});
});
describe('when given no parameters', function () {
it('should return a random departure and arrival', function () {
flightGenerator = new FlightGenerator_1.FlightGenerator();
var flight = flightGenerator.generateFlight();
expect(flight.departure.randomlyGenerated).toBe(true);
expect(flight.arrival.randomlyGenerated).toBe(true);
});
});
});
describe('findMatchingAirport', function () {
beforeAll(function () {
flightGenerator = new FlightGenerator_1.FlightGenerator({
minDistance: 15,
maxDistance: 200,
excludeCountries: ['AU', 'CA'],
});
});
it('should a randomly selected airport', function () {
var outputAirport = flightGenerator.findMatchingAirport();
expect(outputAirport.randomlyGenerated).toBe(true);
});
it('should return an airport within the min max distance', function () {
var inputAirport = AirportUtils_1.AirportUtils.getAirport('KMIA');
var outputAirport = flightGenerator.findMatchingAirport(inputAirport);
var flight = new Flight_1.Flight(inputAirport, outputAirport);
expect(flight.getDistance()).toBeGreaterThan(15);
expect(flight.getDistance()).toBeLessThan(200);
});
it('should return the same airport if no match is found', function () {
flightGenerator = new FlightGenerator_1.FlightGenerator({
minDistance: 15,
maxDistance: 15,
});
var inputAirport = AirportUtils_1.AirportUtils.getAirport('KMIA');
var outputAirport = flightGenerator.findMatchingAirport(inputAirport);
var flight = new Flight_1.Flight(inputAirport, outputAirport);
expect(flight.departure).toBe(flight.arrival);
expect(flight.isValid()).toBe(false);
});
});