/
NikolayIvkin
/
TheAlgorithms
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/test/java/com/thealgorithms/stacks/PrefixEvaluatorTest.java
27 строк
871 B
Hardik Pawar
feat: Add `PrefixEvaluator` new algorithm with Junit tests (#5755)
13 окт 2024, 13:57
Не верифицирован
13 окт 2024, 13:57
bae7f89
Код
Авторство
О чём код?
package com.thealgorithms.stacks; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.EmptyStackException; import org.junit.jupiter.api.Test; public class PrefixEvaluatorTest { @Test public void testValidExpressions() { assertEquals(10, PrefixEvaluator.evaluatePrefix("+ * 2 3 4")); assertEquals(5, PrefixEvaluator.evaluatePrefix("- + 7 3 5")); assertEquals(6, PrefixEvaluator.evaluatePrefix("/ * 3 2 1")); } @Test public void testInvalidExpression() { assertThrows(EmptyStackException.class, () -> PrefixEvaluator.evaluatePrefix("+ 3")); } @Test public void testMoreThanOneStackSizeAfterEvaluation() { assertThrows(IllegalArgumentException.class, () -> PrefixEvaluator.evaluatePrefix("+ 3 4 5")); } }