Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
savchukPR2 authored May 29, 2024
1 parent 2641d17 commit 5dca78e
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 43 deletions.
84 changes: 68 additions & 16 deletions modules/bodrov_daniil_fibonacci_heap/CMakeList.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,72 @@
# Declare variables for binaries' names
get_filename_component(DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
set(MODULE "${DIR_NAME}")
set(LIBRARY "lib_${MODULE}")
set(TESTS "test_${MODULE}")
set(APPLICATION "app_${MODULE}")
# Set the prefix for your tests
set(prefix "fibonacci_heap")

# Include directory with public headers
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# Test the run() function
add_test(
NAME ${prefix}_run
COMMAND ${APPLICATION}
)
set_tests_properties(${prefix}_run PROPERTIES
PASS_REGULAR_EXPRESSION "Fibonacci Heap Operations:"
LABELS "${prefix}"
)

# Add all submodules
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(application)
# Test the insert operation
add_test(
NAME ${prefix}_insert
COMMAND ${APPLICATION} --insert
)
set_tests_properties(${prefix}_insert PROPERTIES
PASS_REGULAR_EXPRESSION "Element inserted successfully."
LABELS "${prefix}"
)

#############################################
##### Testing
#############################################
# Test the extract minimum operation
add_test(
NAME ${prefix}_extract_min
COMMAND ${APPLICATION} --extract
)
set_tests_properties(${prefix}_extract_min PROPERTIES
PASS_REGULAR_EXPRESSION "Minimum element extracted:"
LABELS "${prefix}"
)

include("CTestTests.txt")
# Test the decrease key operation
add_test(
NAME ${prefix}_decrease_key
COMMAND ${APPLICATION} --decrease 0 10
)
set_tests_properties(${prefix}_decrease_key PROPERTIES
PASS_REGULAR_EXPRESSION "Key decreased successfully."
LABELS "${prefix}"
)

# Test the delete node operation
add_test(
NAME ${prefix}_delete_node
COMMAND ${APPLICATION} --delete 0
)
set_tests_properties(${prefix}_delete_node PROPERTIES
PASS_REGULAR_EXPRESSION "Node deleted successfully."
LABELS "${prefix}"
)

# Test the merge heaps operation
add_test(
NAME ${prefix}_merge_heaps
COMMAND ${APPLICATION} --merge 2 10 20
)
set_tests_properties(${prefix}_merge_heaps PROPERTIES
PASS_REGULAR_EXPRESSION "Heaps merged successfully."
LABELS "${prefix}"
)

# Test the invalid input
add_test(
NAME ${prefix}_invalid_input
COMMAND ${APPLICATION} --invalid
)
set_tests_properties(${prefix}_invalid_input PROPERTIES
PASS_REGULAR_EXPRESSION "Invalid choice. Please try again."
LABELS "${prefix}"
)
46 changes: 19 additions & 27 deletions modules/bodrov_daniil_fibonacci_heap/src/console.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2024 Savchuk Anton

#include <iostream>
#include <string>
#include "include/console.h"

void Console::run() {
Expand All @@ -12,37 +11,30 @@ void Console::run() {

void Console::printMenu() {
std::cout << "Fibonacci Heap Operations:" << std::endl;
std::cout << "1. Insert Element" << std::endl;
std::cout << "2. Extract Minimum" << std::endl;
std::cout << "3. Decrease Key" << std::endl;
std::cout << "4. Delete Node" << std::endl;
std::cout << "5. Merge Heaps" << std::endl;
std::cout << "--insert : Insert Element" << std::endl;
std::cout << "--extract : Extract Minimum" << std::endl;
std::cout << "--decrease : Decrease Key" << std::endl;
std::cout << "--delete : Delete Node" << std::endl;
std::cout << "--merge : Merge Heaps" << std::endl;
std::cout << "Enter your choice: ";
}

void Console::handleUserInput() {
int choice;
std::string choice;
std::cin >> choice;

switch (choice) {
case 1:
insertElement();
break;
case 2:
extractMinimum();
break;
case 3:
decreaseKey();
break;
case 4:
deleteNode();
break;
case 5:
mergeHeaps();
break;
default:
std::cout << "Invalid choice. Please try again." << std::endl;
break;
if (choice == "--insert") {
insertElement();
} else if (choice == "--extract") {
extractMinimum();
} else if (choice == "--decrease") {
decreaseKey();
} else if (choice == "--delete") {
deleteNode();
} else if (choice == "--merge") {
mergeHeaps();
} else {
std::cout << "Invalid choice. Please try again." << std::endl;
}
}

Expand Down

0 comments on commit 5dca78e

Please sign in to comment.