Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
quick_max
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2867fdfd
authored
Sep 23, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only the first answer is accepted
parent
b1e5f2a7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
8 deletions
app/src/androidTest/java/com/example/quickmax/MainActivityTest.kt
app/src/main/java/com/example/quickmax/MainActivity.kt
app/src/main/res/layout/fragment_response_correct.xml
app/src/main/res/layout/fragment_response_wrong.xml
app/src/androidTest/java/com/example/quickmax/MainActivityTest.kt
View file @
2867fdfd
...
@@ -12,18 +12,16 @@ import androidx.core.view.get
...
@@ -12,18 +12,16 @@ import androidx.core.view.get
import
androidx.test.espresso.ViewAction
import
androidx.test.espresso.ViewAction
import
androidx.test.espresso.UiController
import
androidx.test.espresso.UiController
import
androidx.test.espresso.action.ViewActions.click
import
androidx.test.espresso.action.ViewActions.click
import
androidx.test.espresso.assertion.ViewAssertions.matches
import
androidx.test.espresso.matcher.ViewMatchers.*
import
androidx.test.espresso.matcher.ViewMatchers.*
import
junit.framework.Assert.assertTrue
import
org.hamcrest.Matcher
import
org.hamcrest.Matcher
import
org.junit.Before
import
org.junit.Before
class
MainActivityTest
{
class
MainActivityTest
{
@get
:
Rule
@get
:
Rule
val
testRule
=
ActivityTestRule
<
MainActivity
>(
MainActivity
::
class
.
java
)
val
testRule
=
ActivityTestRule
<
MainActivity
>(
MainActivity
::
class
.
java
)
private
lateinit
var
radioGroup
:
RadioGroup
private
lateinit
var
radioGroup
:
RadioGroup
@Before
@Before
fun
init
()
{
fun
init
()
{
radioGroup
=
testRule
.
activity
.
radio_group
radioGroup
=
testRule
.
activity
.
radio_group
...
@@ -34,7 +32,9 @@ class MainActivityTest {
...
@@ -34,7 +32,9 @@ class MainActivityTest {
val
correctAnswerIndex
=
getCorrectAnswerIndex
()
val
correctAnswerIndex
=
getCorrectAnswerIndex
()
val
correctAnswerId
=
radioGroup
[
correctAnswerIndex
].
id
val
correctAnswerId
=
radioGroup
[
correctAnswerIndex
].
id
onView
(
withId
(
correctAnswerId
)).
perform
(
click
())
onView
(
withId
(
correctAnswerId
)).
perform
(
click
())
onView
(
withId
(
R
.
id
.
response
)).
check
(
matches
(
withText
(
R
.
string
.
response_correct
)))
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
.
size
==
1
)
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
[
0
]
is
ResponseCorrectFragment
)
}
}
@Test
@Test
...
@@ -43,9 +43,20 @@ class MainActivityTest {
...
@@ -43,9 +43,20 @@ class MainActivityTest {
val
wrongAnswerIndex
=
if
(
correctAnswerIndex
==
3
)
2
else
3
val
wrongAnswerIndex
=
if
(
correctAnswerIndex
==
3
)
2
else
3
val
wrongAnswerId
=
radioGroup
[
wrongAnswerIndex
].
id
val
wrongAnswerId
=
radioGroup
[
wrongAnswerIndex
].
id
onView
(
withId
(
wrongAnswerId
)).
perform
(
click
())
onView
(
withId
(
wrongAnswerId
)).
perform
(
click
())
onView
(
withId
(
R
.
id
.
response
)).
check
(
matches
(
withText
(
R
.
string
.
response_wrong
)))
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
.
size
==
1
)
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
[
0
]
is
ResponseWrongFragment
)
}
}
@Test
fun
only_fist_answer_accepted
()
{
onView
(
withId
(
radioGroup
[
0
].
id
)).
perform
(
click
())
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
.
size
==
1
)
onView
(
withId
(
radioGroup
[
1
].
id
)).
perform
(
click
())
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
.
size
==
1
)
}
private
fun
getCorrectAnswerIndex
():
Int
{
private
fun
getCorrectAnswerIndex
():
Int
{
val
options
=
getOptions
()
val
options
=
getOptions
()
val
correctAnswer
=
findSecondMax
(
options
)
val
correctAnswer
=
findSecondMax
(
options
)
...
...
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
2867fdfd
...
@@ -10,6 +10,7 @@ import kotlinx.android.synthetic.main.activity_main.*
...
@@ -10,6 +10,7 @@ import kotlinx.android.synthetic.main.activity_main.*
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
var
numberSet
=
NumberSet
(
4
,
3
)
var
numberSet
=
NumberSet
(
4
,
3
)
private
var
toAcceptAnswer
=
true
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
...
@@ -29,6 +30,9 @@ class MainActivity : AppCompatActivity() {
...
@@ -29,6 +30,9 @@ class MainActivity : AppCompatActivity() {
}
}
private
fun
processAnswer
(
answer
:
Int
)
{
private
fun
processAnswer
(
answer
:
Int
)
{
if
(!
toAcceptAnswer
)
return
toAcceptAnswer
=
false
val
responseFragment
:
Fragment
=
if
(
numberSet
.
isCorrect
(
answer
))
{
val
responseFragment
:
Fragment
=
if
(
numberSet
.
isCorrect
(
answer
))
{
ResponseCorrectFragment
.
newInstance
()
ResponseCorrectFragment
.
newInstance
()
}
else
}
else
...
...
app/src/main/res/layout/fragment_response_correct.xml
View file @
2867fdfd
...
@@ -25,7 +25,6 @@
...
@@ -25,7 +25,6 @@
app:srcCompat=
"@drawable/ic_double_arrow"
/>
app:srcCompat=
"@drawable/ic_double_arrow"
/>
<TextView
<TextView
android:id=
"@+id/response"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"24dp"
android:layout_marginStart=
"24dp"
...
...
app/src/main/res/layout/fragment_response_wrong.xml
View file @
2867fdfd
...
@@ -11,7 +11,6 @@
...
@@ -11,7 +11,6 @@
app:layout_constraintStart_toStartOf=
"parent"
>
app:layout_constraintStart_toStartOf=
"parent"
>
<ImageButton
<ImageButton
android:id=
"@+id/imageButton"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginTop=
"8dp"
...
@@ -25,7 +24,6 @@
...
@@ -25,7 +24,6 @@
app:srcCompat=
"@drawable/ic_double_arrow"
/>
app:srcCompat=
"@drawable/ic_double_arrow"
/>
<TextView
<TextView
android:id=
"@+id/response"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"24dp"
android:layout_marginStart=
"24dp"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment