From 28d115f934c017b77bbbc7fed53308f153ecc362 Mon Sep 17 00:00:00 2001 From: Elias Afara Date: Thu, 26 Oct 2023 23:05:49 +0200 Subject: [PATCH] Enhancement: Refactor algorithm creation script for user-friendly simplicity --- README.md | 6 +++--- create_algorithm.sh | 25 ++++++++++++------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a1d36f5..293d82c 100644 --- a/README.md +++ b/README.md @@ -77,16 +77,16 @@ To create new algorithm and test files, follow these steps: 1. Open your terminal and navigate to the root directory of the repository. -2. Use the following command to create a new algorithm and its corresponding test file. Replace ``, ``, and `` with your desired values: +2. Use the following command to create a new algorithm and its corresponding test file. Replace ``, `` with your desired values: ```bash - npm run create-algorithm + npm run create-algorithm ``` For example: ```bash - npm run create-algorithm Searching BinarySearch.js BinarySearch.test.js + npm run create-algorithm Searching BinarySearch ``` 3. The script will create the specified algorithm and test files in the appropriate category folder. diff --git a/create_algorithm.sh b/create_algorithm.sh index ddb432a..7a8ba44 100755 --- a/create_algorithm.sh +++ b/create_algorithm.sh @@ -1,27 +1,26 @@ #!/bin/bash # Check if the correct number of arguments is provided -if [ "$#" -ne 3 ]; then - echo "Usage: $0 " +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " exit 1 fi category="$1" -algorithm_js="$2" -algorithm_test_js="$3" +algorithm="$2" category_path="${category}/tests" # Create the category directory and the tests directory if they don't exist mkdir -p "$category_path" -# Create the algorithm file -algorithm_file_path="${category}/${algorithm_js}" -touch "$algorithm_file_path" -echo "// Implement your algorithm here" > "$algorithm_file_path" +# Create the algorithm.js file +algorithm_js="${category}/${algorithm}.js" +touch "$algorithm_js" +echo "// Implement your algorithm here" > "$algorithm_js" -# Create the test file -test_file_path="${category_path}/${algorithm_test_js}" -touch "$test_file_path" -echo "// Implement tests for your algorithm here" > "$test_file_path" +# Create the algorithm.test.js file +algorithm_test_js="${category_path}/${algorithm}.test.js" +touch "$algorithm_test_js" +echo "// Implement tests for your algorithm here" > "$algorithm_test_js" -echo "Created $algorithm_file_path and $test_file_path" +echo "Created $algorithm_js and $algorithm_test_js"