{"id":22449913,"url":"https://github.com/turskyi/stringcalculator","last_synced_at":"2025-03-27T12:16:31.736Z","repository":{"id":133704783,"uuid":"483784554","full_name":"Turskyi/StringCalculator","owner":"Turskyi","description":"A simple Java program that evaluates mathematical expressions provided as strings. Demonstrates Test-Driven Development (TDD) with comprehensive tests using JUnit and Mockito.","archived":false,"fork":false,"pushed_at":"2024-07-21T13:55:36.000Z","size":13315,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T16:28:33.664Z","etag":null,"topics":["java","junit","junit5","software-development","string-calculator","tdd","test-driven-development","unit-testing"],"latest_commit_sha":null,"homepage":"https://github.com/Turskyi/StringCalculator","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Turskyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-20T19:19:30.000Z","updated_at":"2024-07-22T22:17:52.000Z","dependencies_parsed_at":"2025-02-01T16:38:28.357Z","dependency_job_id":null,"html_url":"https://github.com/Turskyi/StringCalculator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Turskyi%2FStringCalculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Turskyi%2FStringCalculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Turskyi%2FStringCalculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Turskyi%2FStringCalculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Turskyi","download_url":"https://codeload.github.com/Turskyi/StringCalculator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245841761,"owners_count":20681195,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","junit","junit5","software-development","string-calculator","tdd","test-driven-development","unit-testing"],"created_at":"2024-12-06T05:12:25.752Z","updated_at":"2025-03-27T12:16:31.703Z","avatar_url":"https://github.com/Turskyi.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)\n\u003cimg alt=\"GitHub commit activity\" src=\"https://img.shields.io/github/commit-activity/m/Turskyi/StringCalculator\"\u003e\n\n# String Calculator\n\n## Project Description\n\nThe String Calculator is a simple terminal-based Java program that can\nevaluate mathematical expressions provided as strings.\nIt supports various features such as custom delimiters,\nhandling new lines, and ignoring numbers larger than 1000.\nThis project is a great exercise for beginners to practice string manipulation,\nexception handling, and test-driven development (TDD) in Java.\nThis project also includes comprehensive tests to validate the functionality\nand ensure the requirements are met.\n\n## Features\n\nProgramming language: [Java](https://www.oracle.com/java/);\n\n1. **Basic Addition**: The `add` method can add numbers separated by commas.\n   - Example: `\"1,2,5\"` will return `8`.\n2. **Handling New Lines**: The `add` method can handle new lines in the input.\n   - Example: `\"1\\n,2,3\"` will return `6`.\n3. **Custom Delimiters**: The `add` method supports custom delimiters specified\n   at the beginning of the string.\n   - Format: `\"//[delimiter]\\n[numbers]\"`\n   - Example: `\"//;\\n1;3;4\"` will return `8`.\n4. **Negative Numbers**: Calling `add` with a negative number will throw an\n   exception with a message listing the negative numbers.\n   - Example: `\"1,-2,3\"` will throw an\n     exception: `\"Negatives not allowed: [-2]\"`.\n5. **Ignoring Large Numbers**: Numbers larger than 1000 are ignored.\n   - Example: `\"2,1001\"` will return `2`.\n6. **Arbitrary Length Delimiters**: Custom delimiters can be of arbitrary\n   length.\n   - Example: `\"//***\\n1***2***3\"` will return `6`.\n7. **Multiple Delimiters**: The `add` method supports multiple delimiters.\n   - Example: `\"//$,@\\n1$2@3\"` will return `6`.\n\n## The goal of the program:\n\n1. Create a simple String calculator with a method \"int Add(string numbers)\":\n   a. The numbers in the string are separated by a comma.\n   b. Empty strings should return 0.\n   c. The return type should be an integer.\n   d. Example input: “1,2,5”—expected result: “8.”\n   e. Write tests to prove your input validates.\n2. Change the Add method to handle new lines in the input format:\n   a. Example: “1\\n,2,3” - Result: “6”\n   b. Example 2: “1,\\n2,4”—Result: “7”\n3. Support a custom delimiter:\n   a.\n   The beginning of your string will now contain a small control code\n   that lets you\n   set a custom delimiter.\n   b. Format: “//[delimiter]\\n[delimiter separated numbers]”\n   c.\n   Example: “//;\\n1;3;4” - Result: 8\n   d.\n   In the above you can see that following the double forward slash we set a\n   semicolon, followed by a new line.\n   We then use that delimiter to split our\n   numbers.\n   e.\n   e.\n   Other examples\n   i.\n   “//$\\n1$2$3” - Result: 6\n   ii. “//@\\n2@3@8” - Result: 13\n4. Calling add with a negative number should throw an exception:\n   “Negatives not allowed.”\n   The exception should list the number(s) that caused the exception\n\n   ### Bonus:\n5. Numbers larger than 1000 should be ignored.\n   a.\n   Example “2,1001”—Result: 2\n6. Delimiters can be arbitrary length\n   a. “//\\*\\*\\*\\n1\\*\\*\\*2\\*\\*\\*3” - Result 6\n7. Allow for multiple delimiters\n   a. “//$,@\\n1$2@3” - Result 6\n8. Combine 2 and 3 bonus questions. Allow multiple delimiters of arbitrary\n   length.\n\n## Tests\n\nThe String Calculator project includes comprehensive tests to validate the\nfunctionality and ensure the requirements are met.\nThese tests cover various scenarios such as handling empty strings, custom\ndelimiters, negative numbers, and more.\nTo run the tests, use your preferred Java IDE or a build tool like Maven or\nGradle.\n\n### Example Test\n\n```java\npublic class StringCalculatorTest {\n\n   @Test\n   public final void whenEmptyStringIsUsedThenReturnValueIs0() {\n      assertEquals (0, StringCalculator.add (\"\"));\n   }\n}\n```\n\n## Usage\n\nTo use the String Calculator, call the `add` method with a string containing\nthe numbers you want to add.\nThe method will return the sum of the numbers.\nYou can specify custom delimiters and handle new lines as described in the\nfeatures section.\n\n**Educational Value**:\nIt can serve as a good example for learning and practicing TDD,\nstring parsing, and basic arithmetic operations in Java.\n\n**Code Reuse**:\nThe code can be reused or extended for other projects\nthat require string-based calculations.\n\n### Example Code\n\n```java\npublic class Main {\n   public static void main(String[] args) {\n      final int result = StringCalculator.add (\"//$,@\\n1$2@3\");\n      System.out.println (\"Result: \" + result); // Output: Result: 6\n   }\n}\n```\n\n## Installation Instructions\n\n1. Download the project.\n2. Open the project in your preferred Java IDE (e.g., IntelliJ IDEA, Eclipse).\n3. Compile and run the `Main` class to see the String Calculator in action.\n4. Compile and run the `StringCalculatorTest` class to see the tests in action\n   and validate the functionality.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturskyi%2Fstringcalculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fturskyi%2Fstringcalculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturskyi%2Fstringcalculator/lists"}