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
d19c7892
authored
Sep 23, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MainActivityTest; WIP response as a fragment
parent
23812f13
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
182 additions
and
14 deletions
.idea/vcs.xml
app/build.gradle
app/src/androidTest/java/com/example/quickmax/MainActivityTest.kt
app/src/main/java/com/example/quickmax/MainActivity.kt
app/src/main/java/com/example/quickmax/ResponseFragment.kt
app/src/main/res/drawable/ic_double_arrow.xml
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/fragment_response.xml
app/src/main/res/values/strings.xml
.idea/vcs.xml
0 → 100644
View file @
d19c7892
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
app/build.gradle
View file @
d19c7892
...
...
@@ -14,6 +14,7 @@ android {
versionCode
1
versionName
"1.0"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
vectorDrawables
.
useSupportLibrary
=
true
}
buildTypes
{
release
{
...
...
app/src/androidTest/java/com/example/quickmax/MainActivityTest.kt
View file @
d19c7892
package
com.example.quickmax
import
android.view.View
import
android.widget.RadioGroup
import
androidx.test.espresso.Espresso.onView
import
androidx.test.rule.ActivityTestRule
import
kotlinx.android.synthetic.main.activity_main.*
import
org.junit.Rule
import
org.junit.Test
import
android.widget.TextView
import
androidx.core.view.get
import
androidx.test.espresso.ViewAction
import
androidx.test.espresso.UiController
import
androidx.test.espresso.action.ViewActions.click
import
androidx.test.espresso.assertion.ViewAssertions.matches
import
androidx.test.espresso.matcher.ViewMatchers.*
import
org.hamcrest.Matcher
import
org.junit.Before
class
MainActivityTest
{
@get
:
Rule
val
testRule
=
ActivityTestRule
<
MainActivity
>(
MainActivity
::
class
.
java
)
private
lateinit
var
radioGroup
:
RadioGroup
@Before
fun
init
()
{
radioGroup
=
testRule
.
activity
.
radio_group
}
@Test
fun
test
()
{
testRule
.
activity
.
radio_group
.
getChildAt
(
0
)
fun
correct_answer_marked_as_correct
()
{
val
correctAnswerIndex
=
getCorrectAnswerIndex
()
val
correctAnswerId
=
radioGroup
[
correctAnswerIndex
].
id
onView
(
withId
(
correctAnswerId
)).
perform
(
click
())
onView
(
withId
(
R
.
id
.
response
)).
check
(
matches
(
withText
(
R
.
string
.
response_correct
)))
}
@Test
fun
wrong_answer_marked_as_wrong
()
{
val
correctAnswerIndex
=
getCorrectAnswerIndex
()
val
wrongAnswerIndex
=
if
(
correctAnswerIndex
==
3
)
2
else
3
val
wrongAnswerId
=
radioGroup
[
wrongAnswerIndex
].
id
onView
(
withId
(
wrongAnswerId
)).
perform
(
click
())
onView
(
withId
(
R
.
id
.
response
)).
check
(
matches
(
withText
(
R
.
string
.
response_wrong
)))
}
private
fun
getCorrectAnswerIndex
():
Int
{
val
options
=
getOptions
()
val
correctAnswer
=
findSecondMax
(
options
)
return
options
.
indexOf
(
correctAnswer
)
}
private
fun
getOptions
():
MutableList
<
Int
>
{
val
options
=
mutableListOf
<
Int
>()
for
(
i
in
0
until
radioGroup
.
childCount
)
options
.
add
(
getText
(
withId
(
radioGroup
[
i
].
id
)).
toInt
())
return
options
}
private
fun
getText
(
matcher
:
Matcher
<
View
>):
String
{
var
text
=
""
onView
(
matcher
).
perform
(
object
:
ViewAction
{
override
fun
getConstraints
():
Matcher
<
View
>
{
return
isAssignableFrom
(
TextView
::
class
.
java
)
}
override
fun
getDescription
():
String
{
return
""
}
override
fun
perform
(
uiController
:
UiController
,
view
:
View
)
{
val
tv
=
view
as
TextView
text
=
tv
.
text
.
toString
()
}
})
return
text
}
}
\ No newline at end of file
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
d19c7892
...
...
@@ -28,8 +28,10 @@ class MainActivity : AppCompatActivity() {
}
private
fun
processAnswer
(
answer
:
Int
)
{
if
(
numberSet
.
isCorrect
(
answer
))
if
(
numberSet
.
isCorrect
(
answer
))
{
response
.
text
=
getString
(
R
.
string
.
response_correct
)
}
else
response
.
text
=
getString
(
R
.
string
.
response_wrong
)
}
...
...
app/src/main/java/com/example/quickmax/ResponseFragment.kt
0 → 100644
View file @
d19c7892
package
com.example.quickmax
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
class
ResponseFragment
:
Fragment
()
{
companion
object
{
fun
newInstance
():
ResponseFragment
{
return
ResponseFragment
()
}
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_response
,
container
,
false
)
}
}
\ No newline at end of file
app/src/main/res/drawable/ic_double_arrow.xml
0 → 100644
View file @
d19c7892
<vector
android:height=
"80dp"
android:viewportHeight=
"24"
android:viewportWidth=
"24"
android:width=
"80dp"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<path
android:fillColor=
"#FF000000"
android:pathData=
"M15.5,5l-4.5,0l5,7l-5,7l4.5,0l5,-7z"
/>
<path
android:fillColor=
"#FF000000"
android:pathData=
"M8.5,5l-4.5,0l5,7l-5,7l4.5,0l5,-7z"
/>
</vector>
app/src/main/res/layout/activity_main.xml
View file @
d19c7892
...
...
@@ -7,15 +7,6 @@
tools:context=
".MainActivity"
>
<TextView
android:id=
"@+id/response"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"8dp"
android:layout_marginBottom=
"8dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
/>
<TextView
android:id=
"@+id/task"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
...
...
@@ -25,6 +16,42 @@
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/response_layout"
android:layout_width=
"0dp"
android:layout_height=
"120dp"
android:background=
"#4CAF50"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
>
<ImageButton
android:id=
"@+id/imageButton"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginEnd=
"24dp"
android:layout_marginBottom=
"8dp"
android:background=
"#009C27B0"
android:tint=
"#FFFFFF"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:srcCompat=
"@drawable/ic_double_arrow"
/>
<TextView
android:id=
"@+id/response"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"24dp"
android:textColor=
"@android:color/white"
android:textSize=
"30sp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
tools:text=
"@string/response_correct"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<RadioGroup
android:id=
"@+id/radio_group"
android:layout_width=
"wrap_content"
...
...
app/src/main/res/layout/fragment_response.xml
0 → 100644
View file @
d19c7892
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/response_layout"
android:layout_width=
"0dp"
android:layout_height=
"120dp"
android:background=
"#4CAF50"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
>
<ImageButton
android:id=
"@+id/imageButton"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginEnd=
"24dp"
android:layout_marginBottom=
"8dp"
android:background=
"#009C27B0"
android:tint=
"#FFFFFF"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:srcCompat=
"@drawable/ic_double_arrow"
/>
<TextView
android:id=
"@+id/response"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"24dp"
android:textColor=
"@android:color/white"
android:textSize=
"30sp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
tools:text=
"@string/response_correct"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
d19c7892
<resources>
<string
name=
"app_name"
>
QuickMax
</string>
<string
name=
"second_max"
>
Выберите второе наибольшее число
</string>
<string
name=
"response_correct"
>
C
orrect!
</string>
<string
name=
"response_wrong"
>
W
rong!
</string>
<string
name=
"response_correct"
>
C
ORRECT
</string>
<string
name=
"response_wrong"
>
W
RONG
</string>
</resources>
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