Download benchmarks/java/StringCalculator.java from SevdanurGenc/LLM-Automated-Test-Generation-Agent: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/java/StringCalculator.java
- Command line
-
hf download hf://SevdanurGenc/LLM-Automated-Test-Generation-Agent/benchmarks/java/StringCalculator.java
-
curl -L -o StringCalculator.java https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/java/StringCalculator.java
1.82 kB
| import java.util.ArrayList; | |
| import java.util.List; | |
| /** | |
| * "String Calculator" katası: | |
| * - "" -> 0 | |
| * - virgül veya satır sonu ile ayrılmış sayıları toplar: "1,2\n3" -> 6 | |
| * - özel ayraç: "//;\n1;2" -> 3 | |
| * - negatif sayılar: IllegalArgumentException("negatives not allowed: -1, -3") | |
| * - 1000'den büyük sayılar yok sayılır | |
| */ | |
| public class StringCalculator { | |
| public int add(String input) { | |
| if (input == null || input.isEmpty()) { | |
| return 0; | |
| } | |
| String delimiters = ",|\n"; | |
| String body = input; | |
| if (input.startsWith("//")) { | |
| int nl = input.indexOf('\n'); | |
| if (nl < 0) { | |
| throw new IllegalArgumentException("missing newline after delimiter"); | |
| } | |
| String custom = input.substring(2, nl); | |
| delimiters = java.util.regex.Pattern.quote(custom); | |
| body = input.substring(nl + 1); | |
| } | |
| int sum = 0; | |
| List<Integer> negatives = new ArrayList<>(); | |
| for (String token : body.split(delimiters)) { | |
| if (token.isBlank()) { | |
| throw new IllegalArgumentException("empty number"); | |
| } | |
| int value = Integer.parseInt(token.trim()); | |
| if (value < 0) { | |
| negatives.add(value); | |
| } else if (value <= 1000) { | |
| sum += value; | |
| } | |
| } | |
| if (!negatives.isEmpty()) { | |
| StringBuilder sb = new StringBuilder("negatives not allowed: "); | |
| for (int i = 0; i < negatives.size(); i++) { | |
| if (i > 0) { | |
| sb.append(", "); | |
| } | |
| sb.append(negatives.get(i)); | |
| } | |
| throw new IllegalArgumentException(sb.toString()); | |
| } | |
| return sum; | |
| } | |
| } | |