From bdd06f9252612e07f19aa2921a4c9ff597344a71 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Tue, 5 Nov 2024 16:47:35 +0000 Subject: [PATCH] Implement pushing to reverse polish stack Co-Authored-By: td1223 --- src/main/java/ic/doc/ReversePolishStack.java | 10 +++++++++- src/test/java/ic/doc/ReversePolishStackTest.java | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/ic/doc/ReversePolishStack.java b/src/main/java/ic/doc/ReversePolishStack.java index fc0d0a0..ff6f0f9 100644 --- a/src/main/java/ic/doc/ReversePolishStack.java +++ b/src/main/java/ic/doc/ReversePolishStack.java @@ -1,7 +1,15 @@ package ic.doc; +import java.util.Stack; + public class ReversePolishStack { + private final Stack stack = new Stack<>(); + public int getSize() { - return 0; + return stack.size(); + } + + public void push(IntOperator intOperator) { + stack.push(intOperator); } } diff --git a/src/test/java/ic/doc/ReversePolishStackTest.java b/src/test/java/ic/doc/ReversePolishStackTest.java index 5fff47e..ba2bca0 100644 --- a/src/test/java/ic/doc/ReversePolishStackTest.java +++ b/src/test/java/ic/doc/ReversePolishStackTest.java @@ -12,4 +12,12 @@ public class ReversePolishStackTest { public void reversePolishStackEmptyInitially() { assertThat(reversePolishStack.getSize(), is(0)); } + + @Test + public void canPushToReversePolishStack() { + reversePolishStack.push(new IntOperator(0, args -> 1)); + assertThat(reversePolishStack.getSize(), is(1)); + reversePolishStack.push(new IntOperator(0, args -> 2)); + assertThat(reversePolishStack.getSize(), is(2)); + } }