From a7eb01da36722c07d212848d6e0e2de9fb7a0fe7 Mon Sep 17 00:00:00 2001 From: Marcel Schanes Date: Wed, 3 Jun 2020 09:05:51 +0200 Subject: [PATCH 1/5] GAMES_000J changed some hangman tests [LD, SM] --- .../com/swt20/swt_morning2/HangmanTests.java | 18 ++++++++---------- .../swt_morning2/HangmanGameFragment.java | 4 +++- app/src/main/res/layout/hangman_game.xml | 4 +--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/src/androidTest/java/com/swt20/swt_morning2/HangmanTests.java b/app/src/androidTest/java/com/swt20/swt_morning2/HangmanTests.java index dd0a374..c4c3f8e 100644 --- a/app/src/androidTest/java/com/swt20/swt_morning2/HangmanTests.java +++ b/app/src/androidTest/java/com/swt20/swt_morning2/HangmanTests.java @@ -73,13 +73,15 @@ public void playGame() { } assertThat(st.getScore(Game.HANGMAN), is(oldScore + 1)); return; - } catch (Exception e) { + } catch (AssertionError e) { // View not displayed } } assert (false); } + + @Test public void playGameTwice() { @@ -102,7 +104,7 @@ public void playGameTwice() { } else { return; } - } catch (Exception e) { + } catch (AssertionError e) { // View not displayed } } @@ -133,7 +135,7 @@ public void pressWrongLetterTwice() { matches(withDrawable(R.drawable.hangman_1))); return; // View displayed - } catch (Exception e) { + } catch (AssertionError e) { // View not displayed } } @@ -154,15 +156,10 @@ public void pressLetterMoreThanNineTimes() { for (int i = 0; i < 12; i++) { onView(withId(R.id.plainText_nextChar)).perform(typeText(letter)); try { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // View not displayed - } onView(withId(R.id.button_playagain)).check(matches(isDisplayed())); return; // View displayed - } catch (Exception e) { + } catch (AssertionError e) { // View not displayed } } @@ -262,6 +259,7 @@ public void doubleAddCustomWord() { } + @Test public void scoreReduced() { Activity activity = activityRule.getActivity(); ScoreTracker st = new ScoreTracker(activity.getApplicationContext()); @@ -282,7 +280,7 @@ public void scoreReduced() { onView(isRoot()).perform(pressBack()); // View displayed break; - } catch (Exception e) { + } catch (AssertionError e) { // View not displayed } } diff --git a/app/src/main/java/com/swt20/swt_morning2/HangmanGameFragment.java b/app/src/main/java/com/swt20/swt_morning2/HangmanGameFragment.java index 71fd4c3..11d2606 100644 --- a/app/src/main/java/com/swt20/swt_morning2/HangmanGameFragment.java +++ b/app/src/main/java/com/swt20/swt_morning2/HangmanGameFragment.java @@ -89,9 +89,11 @@ public void onClick(View view) { for (int i = 0; i < word2guess.length(); i++) { word2guessViewtext += "_ "; } + textViewWord2Guess.setVisibility(View.VISIBLE); textViewWord2Guess.setText(word2guessViewtext); textView.setVisibility(View.VISIBLE); nextChar.setVisibility(View.VISIBLE); + view.findViewById(R.id.button_playagain).setVisibility(View.INVISIBLE); feedbackView.setImageResource(0); mainView.findViewById(R.id.button_hangman_hint).setVisibility(View.VISIBLE); @@ -221,7 +223,7 @@ private void gameFinished(int points, String text, View view) { textView.setVisibility(View.INVISIBLE); nextChar.setVisibility(View.INVISIBLE); view.findViewById(R.id.button_hangman_hint).setVisibility(View.INVISIBLE); - + textViewWord2Guess.setVisibility(View.INVISIBLE); } } diff --git a/app/src/main/res/layout/hangman_game.xml b/app/src/main/res/layout/hangman_game.xml index c7319aa..f2f5d4f 100644 --- a/app/src/main/res/layout/hangman_game.xml +++ b/app/src/main/res/layout/hangman_game.xml @@ -25,12 +25,10 @@ android:layout_height="wrap_content" android:text="@string/hangman_playagain" android:visibility="invisible" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.498" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/textView_word2guess" - app:layout_constraintVertical_bias="0.482" /> + app:layout_constraintTop_toBottomOf="@+id/feedbackView" /> Date: Wed, 3 Jun 2020 09:07:58 +0200 Subject: [PATCH 2/5] GAMES_000J added tictactoe test [LD, SM] --- .../swt20/swt_morning2/TicTacToeTests.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/src/androidTest/java/com/swt20/swt_morning2/TicTacToeTests.java b/app/src/androidTest/java/com/swt20/swt_morning2/TicTacToeTests.java index 49a32d4..de03aef 100644 --- a/app/src/androidTest/java/com/swt20/swt_morning2/TicTacToeTests.java +++ b/app/src/androidTest/java/com/swt20/swt_morning2/TicTacToeTests.java @@ -250,4 +250,28 @@ public void autoplayerExists() { } } } + @Test + public void playToDraw() { + onView(withId(R.id.ticTacToeButton)).perform(click()); + onView(withId(R.id.ttt_menu_button)).perform(click()); + onView(withId(R.id.imageView)).perform(click()); + onView(withId(R.id.imageView7)).perform(click()); + onView(withId(R.id.imageView8)).perform(click()); + onView(withId(R.id.imageView3)).perform(click()); + onView(withId(R.id.imageView2)).perform(click()); + onView(withId(R.id.imageView9)).perform(click()); + onView(withId(R.id.imageView6)).perform(click()); + onView(withId(R.id.imageView5)).perform(click()); + onView(withId(R.id.imageView4)).perform(click()); + try { + onView(withId(R.id.ttt_menu_button)).check(matches(isDisplayed())); + } catch (Exception e) { + assert (true); + return; + } + assert (false); + + } + + } From 17ef1f047d8bd73e1bbe90ccc7ee5ec7ab584d9c Mon Sep 17 00:00:00 2001 From: Marcel Schanes Date: Wed, 3 Jun 2020 09:46:48 +0200 Subject: [PATCH 3/5] GAMES_000J changed a testcase and moved a button a bit in hangman [LD, SM] --- .../java/com/swt20/swt_morning2/HangmanTests.java | 10 +++++----- app/src/main/res/layout/hangman_game.xml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/androidTest/java/com/swt20/swt_morning2/HangmanTests.java b/app/src/androidTest/java/com/swt20/swt_morning2/HangmanTests.java index c4c3f8e..06703ed 100644 --- a/app/src/androidTest/java/com/swt20/swt_morning2/HangmanTests.java +++ b/app/src/androidTest/java/com/swt20/swt_morning2/HangmanTests.java @@ -121,7 +121,7 @@ public void pressWrongLetterTwice() { // Go from Hangman Menu to Game onView(withId(R.id.hangmanStartGameButton)).perform(click()); - String letter = "y"; + String letter = "."; for (int i = 0; i < 2; i++) { onView(withId(R.id.plainText_nextChar)).perform(typeText(letter)); @@ -151,7 +151,7 @@ public void pressLetterMoreThanNineTimes() { // Go from Hangman Menu to Game onView(withId(R.id.hangmanStartGameButton)).perform(click()); - String letter = "a"; + String letter = "."; for (int i = 0; i < 12; i++) { onView(withId(R.id.plainText_nextChar)).perform(typeText(letter)); @@ -270,8 +270,8 @@ public void scoreReduced() { // Go from Hangman Menu to Game onView(withId(R.id.hangmanStartGameButton)).perform(click()); - String letter = "a"; - for (int i = 0; i <= 9; i++) { + String letter = "."; + for (int i = 0; i <= 12; i++) { onView(withId(R.id.plainText_nextChar)).perform(typeText(letter)); try { onView(withId(R.id.button_playagain)).check(matches(isDisplayed())); @@ -285,7 +285,7 @@ public void scoreReduced() { } } try { - Thread.sleep(5000); + Thread.sleep(100); } catch (InterruptedException e) { // View not displayed } diff --git a/app/src/main/res/layout/hangman_game.xml b/app/src/main/res/layout/hangman_game.xml index f2f5d4f..3f386a5 100644 --- a/app/src/main/res/layout/hangman_game.xml +++ b/app/src/main/res/layout/hangman_game.xml @@ -81,7 +81,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hangman_hint_button_text" - app:layout_constraintBottom_toTopOf="@+id/button_playagain" + app:layout_constraintBottom_toTopOf="@+id/plainText_nextChar" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView_word2guess" /> From 6c4719efea5ec8c9a0acbb52d5e9864355036b8c Mon Sep 17 00:00:00 2001 From: Marcel Schanes Date: Wed, 3 Jun 2020 10:53:08 +0200 Subject: [PATCH 4/5] GAMES_000J changed a few tictactoe tests which did fail sometimes [LD, SM] --- .../swt20/swt_morning2/TicTacToeTests.java | 20 ++++++++++++++++--- .../swt_morning2/TicTacToeGameFragment.java | 8 ++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/androidTest/java/com/swt20/swt_morning2/TicTacToeTests.java b/app/src/androidTest/java/com/swt20/swt_morning2/TicTacToeTests.java index de03aef..bcd830a 100644 --- a/app/src/androidTest/java/com/swt20/swt_morning2/TicTacToeTests.java +++ b/app/src/androidTest/java/com/swt20/swt_morning2/TicTacToeTests.java @@ -214,13 +214,26 @@ private boolean clickField(int rid, int colourid) { try { onView(withId(rid)).check(matches( EspressoTestsMatchers.withDrawable(R.drawable.empty))); - } catch (Error e) { + } catch (Throwable e) { // Not empty -- continue return false; } - onView(withId(rid)).perform(click()); - onView(withId(rid)).check(matches(EspressoTestsMatchers.withDrawable(colourid))); + try { + onView(withId(rid)).perform(click()); + try { + if (onView(withId(R.id.ttt_menu_button)) != null) { + onView(withId(R.id.ttt_menu_button)).check(matches(isDisplayed())); + } + return false; + } catch (Throwable e) { + //empty + } + onView(withId(rid)).check(matches(EspressoTestsMatchers.withDrawable(colourid))); + } catch (Throwable e) { + onView(withId(R.id.ttt_menu_button)).check(matches(isDisplayed())); + return false; + } return true; } @@ -250,6 +263,7 @@ public void autoplayerExists() { } } } + @Test public void playToDraw() { onView(withId(R.id.ticTacToeButton)).perform(click()); diff --git a/app/src/main/java/com/swt20/swt_morning2/TicTacToeGameFragment.java b/app/src/main/java/com/swt20/swt_morning2/TicTacToeGameFragment.java index fdf23c4..5bf2d94 100644 --- a/app/src/main/java/com/swt20/swt_morning2/TicTacToeGameFragment.java +++ b/app/src/main/java/com/swt20/swt_morning2/TicTacToeGameFragment.java @@ -64,7 +64,7 @@ private void setupCell(final int x, final int y, final ImageView imageView, final TableLayout gameField) { imageView.setImageResource(R.drawable.empty); imageView.setOnClickListener(new View.OnClickListener() { - private void checkWin() { + private boolean checkWin() { TicTacToeGameLogic.Player winner = logic.getWinner(); if (winner != null) { String text; @@ -77,7 +77,9 @@ private void checkWin() { logic.changeScore(winner, tracker); Toast.makeText(getContext(), text, Toast.LENGTH_SHORT).show(); getActivity().onBackPressed(); + return true; } + return false; } @Override @@ -86,7 +88,9 @@ public void onClick(View view) { // outsource to fkt. imageView.setImageResource(logic.getCell(x, y).getOwner().getResId()); - checkWin(); + if(checkWin()) { + return; + } logic.autoplayerTurn(); for (int y = 0; y < gameField.getChildCount(); y++) { final TableRow currentRow = (TableRow) gameField.getChildAt(y); From fbaeb86d8f87e2f4d097220bffbba432ea414519 Mon Sep 17 00:00:00 2001 From: Marcel Schanes Date: Wed, 3 Jun 2020 10:56:04 +0200 Subject: [PATCH 5/5] GAMES_000J fixed linter error [LD, SM] --- .../main/java/com/swt20/swt_morning2/TicTacToeGameFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/swt20/swt_morning2/TicTacToeGameFragment.java b/app/src/main/java/com/swt20/swt_morning2/TicTacToeGameFragment.java index 5bf2d94..cc3a6da 100644 --- a/app/src/main/java/com/swt20/swt_morning2/TicTacToeGameFragment.java +++ b/app/src/main/java/com/swt20/swt_morning2/TicTacToeGameFragment.java @@ -88,7 +88,7 @@ public void onClick(View view) { // outsource to fkt. imageView.setImageResource(logic.getCell(x, y).getOwner().getResId()); - if(checkWin()) { + if (checkWin()) { return; } logic.autoplayerTurn();