pvjc26/du6/test_station.c
2026-05-08 14:16:31 +02:00

65 lines
2.4 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include "a_station.h"
int main() {
printf("=== Testing Train Station Library ===\n\n");
// Test 1: Create station
printf("Test 1: Creating station\n");
struct station* st = create_station();
if (st != NULL) {
printf("Station created successfully\n");
printf("Station has %d tracks\n", st->track_count);
} else {
printf("ERROR: Could not create station\n");
return 1;
}
// Test 2: Add targets
printf("\nTest 2: Adding destinations\n");
add_target_capacity(st, "Bratislava", 100);
add_target_capacity(st, "Kosice", 150);
add_target_capacity(st, "Zilina", 80);
add_target_capacity(st, "Presov", 120);
printf("Added 4 destinations\n");
// Test 3: Count targets
printf("\nTest 3: Counting targets\n");
int target_count = count_targets(st);
printf("Number of targets: %d (expected: 4)\n", target_count);
// Test 4: Get target capacity
printf("\nTest 4: Getting target capacities\n");
printf("Bratislava capacity: %d (expected: 100)\n", get_target_capacity(st, "Bratislava"));
printf("Kosice capacity: %d (expected: 150)\n", get_target_capacity(st, "Kosice"));
printf("Zilina capacity: %d (expected: 80)\n", get_target_capacity(st, "Zilina"));
printf("Presov capacity: %d (expected: 120)\n", get_target_capacity(st, "Presov"));
printf("NonExistent capacity: %d (expected: 0)\n", get_target_capacity(st, "NonExistent"));
// Test 5: Add to existing target
printf("\nTest 5: Adding more capacity to existing target\n");
add_target_capacity(st, "Bratislava", 50);
printf("Bratislava new capacity: %d (expected: 150)\n", get_target_capacity(st, "Bratislava"));
// Test 6: Total capacity count
printf("\nTest 6: Total capacity\n");
int total_capacity = count_capacity(st);
printf("Total capacity: %d (expected: 500)\n", total_capacity);
// Test 7: Hash function consistency
printf("\nTest 7: Hash function consistency\n");
int track1 = select_track(st, "Bratislava");
int track2 = select_track(st, "Bratislava");
printf("Track for 'Bratislava': %d and %d (should be same)\n", track1, track2);
printf("Tracks match: %s\n", track1 == track2 ? "YES" : "NO");
// Test 8: Clean up
printf("\nTest 8: Destroying station\n");
destroy_station(st);
printf("Station destroyed successfully\n");
printf("\n=== All tests completed ===\n");
return 0;
}