Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/htw/berlin/prog2/ha1/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public void pressDigitKey(int digit) {
* im Ursprungszustand ist.
*/
public void pressClearKey() {
if (screen.equals("0")) {
latestValue = 0.0;
latestOperation = "";
}
screen = "0";
latestOperation = "";
latestValue = 0.0;
}

/**
Expand Down Expand Up @@ -83,7 +85,7 @@ public void pressUnaryOperationKey(String operation) {
screen = Double.toString(result);
if(screen.equals("NaN")) screen = "Error";
if(screen.contains(".") && screen.length() > 11) screen = screen.substring(0, 10);

if(screen.endsWith(".0")) screen = screen.substring(0, screen.length() - 2);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/htw/berlin/prog2/ha1/Vector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package htw.berlin.prog2.ha1;

public class Vector {
private int[] _data;
private int _length;
public Vector() {
_data = new int[4];
}
public int get(int position){
int datum = this._data[position];
return datum;
}
public void set(int position, int value){
}
public int getLength(){
return this._length;
}
public void append(int value){

}

public static void main(String[] args){
Vector vector = new Vector();
System.out.println(vector.getLength());
}
}
74 changes: 74 additions & 0 deletions src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@
@DisplayName("Retro calculator")
class CalculatorTest {

@Test
@DisplayName("test regular input 12345")
void testRegularInput() {
//testfall einrichten
Calculator calculator = new Calculator();
calculator.pressDigitKey(1);
calculator.pressDigitKey(2);
calculator.pressDigitKey(3);
calculator.pressDigitKey(4);
calculator.pressDigitKey(5);

//erwartetes ergebniss
String expectedResult = "12345";
String actual = calculator.readScreen();

//vergleich ob test erfolgreich ist
assertEquals(expectedResult, actual);
}

@Test
@DisplayName("should display result after adding two positive multi-digit numbers")
void testPositiveAddition() {
Expand Down Expand Up @@ -90,5 +109,60 @@ void testMultipleDecimalDots() {


//TODO hier weitere Tests erstellen

// Aufgabe 2
@Test
@DisplayName("shouldnt allow multiple oprerrators")
void testMultipleOprerrators() {
Calculator calc = new Calculator();
calc.pressDigitKey(1);
calc.pressDigitKey(2);
calc.pressBinaryOperationKey("+");
calc.pressBinaryOperationKey("-");
calc.pressDigitKey(7);
calc.pressEqualsKey();

String expected = "5";
String actual = calc.readScreen();

assertEquals(expected, actual);

}
//Aufgabe 3
@Test
@DisplayName("should clear completely aufter pressing C")
void testClearComplete() {
Calculator calc = new Calculator();
calc.pressDigitKey(1);
calc.pressBinaryOperationKey("+");
calc.pressDigitKey(7);
calc.pressClearKey();
calc.pressDigitKey(8);
calc.pressEqualsKey();

String expected = "9";
String actual = calc.readScreen();

assertEquals(expected, actual);
}

@Test
@DisplayName("should cut the .0 out the unary resoult")
void testCut() {
Calculator calc = new Calculator();
calc.pressDigitKey(9);
calc.pressDotKey();
calc.pressDigitKey(0);
calc.pressUnaryOperationKey("√");

String expected = "3";
String actual = calc.readScreen();

assertEquals(expected, actual);
}
}