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
0888956b
authored
Sep 24, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Duplicate numbers are not allowed in the answer set
parent
23de08e3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
15 deletions
app/src/androidTest/java/com/example/quickmax/MainActivityTest.kt
app/src/main/java/com/example/quickmax/AnswerSet.kt
app/src/main/java/com/example/quickmax/Calculator.kt
app/src/test/java/com/example/quickmax/AnswerSetTest.kt
app/src/androidTest/java/com/example/quickmax/MainActivityTest.kt
View file @
0888956b
...
@@ -22,11 +22,11 @@ import org.junit.Before
...
@@ -22,11 +22,11 @@ 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
}
}
@Test
@Test
...
...
app/src/main/java/com/example/quickmax/AnswerSet.kt
View file @
0888956b
...
@@ -3,21 +3,26 @@ package com.example.quickmax
...
@@ -3,21 +3,26 @@ package com.example.quickmax
class
AnswerSet
(
numDigits
:
Int
):
Iterable
<
Answer
>
{
class
AnswerSet
(
numDigits
:
Int
):
Iterable
<
Answer
>
{
private
val
buttonIds
=
val
buttonIds
=
listOf
(
R
.
id
.
btn_left_top
,
R
.
id
.
btn_right_top
,
R
.
id
.
btn_left_bottom
,
R
.
id
.
btn_right_bottom
)
listOf
(
R
.
id
.
btn_left_top
,
R
.
id
.
btn_right_top
,
R
.
id
.
btn_left_bottom
,
R
.
id
.
btn_right_bottom
)
private
val
numAnswers
=
4
private
val
numOptions
=
4
private
lateinit
var
correctAnswer
:
Answer
val
numbers
:
MutableList
<
Answer
>
=
MutableList
(
numOptions
)
{
i
->
Answer
(
buttonIds
[
i
],
generateRandom
(
numDigits
))
}
val
answers
:
MutableList
<
Answer
>
=
mutableListOf
()
init
{
init
{
val
correctAnswer
=
findSecondMax
(
numbers
.
map
{
n
->
n
.
value
})
val
randomNumbers
=
generateNRandomNumbers
(
numDigits
,
numAnswers
)
numbers
.
forEach
{
n
->
for
(
i
in
0
until
numAnswers
)
n
.
correct
=
n
.
value
==
correctAnswer
answers
.
add
(
Answer
(
buttonIds
[
i
],
randomNumbers
.
elementAt
(
i
)))
val
correctAnswerNum
=
findSecondMax
(
answers
.
map
{
answer
->
answer
.
value
})
answers
.
forEach
{
n
->
n
.
correct
=
n
.
value
==
correctAnswerNum
if
(
n
.
correct
)
correctAnswer
=
n
}
}
}
}
override
fun
iterator
():
Iterator
<
Answer
>
{
override
fun
iterator
():
Iterator
<
Answer
>
{
return
numb
ers
.
iterator
()
return
answ
ers
.
iterator
()
}
}
}
}
\ No newline at end of file
app/src/main/java/com/example/quickmax/Calculator.kt
View file @
0888956b
...
@@ -8,6 +8,14 @@ fun generateRandom(numDigits: Int): Int {
...
@@ -8,6 +8,14 @@ fun generateRandom(numDigits: Int): Int {
return
(
start
..
end
).
shuffled
().
first
()
return
(
start
..
end
).
shuffled
().
first
()
}
}
fun
generateNRandomNumbers
(
numDigits
:
Int
,
n
:
Int
):
Set
<
Int
>
{
val
randomNumbers
=
setOf
<
Int
>()
while
(
randomNumbers
.
size
<
n
)
{
randomNumbers
.
plus
(
generateRandom
(
numDigits
))
}
return
randomNumbers
}
fun
findSecondMax
(
numbers
:
List
<
Int
>):
Int
{
fun
findSecondMax
(
numbers
:
List
<
Int
>):
Int
{
var
firstMax
=
0
var
firstMax
=
0
var
secondMax
=
0
var
secondMax
=
0
...
...
app/src/test/java/com/example/quickmax/AnswerSetTest.kt
View file @
0888956b
...
@@ -12,13 +12,13 @@ class AnswerSetTest {
...
@@ -12,13 +12,13 @@ class AnswerSetTest {
@Test
@Test
fun
test_constructor
()
{
fun
test_constructor
()
{
assertEquals
(
numOptions
,
numberSet
.
numb
ers
.
size
)
assertEquals
(
numOptions
,
numberSet
.
answ
ers
.
size
)
numberSet
.
numb
ers
.
forEach
{
n
->
n
in
(
100
..
999
)
}
numberSet
.
answ
ers
.
forEach
{
n
->
n
in
(
100
..
999
)
}
}
}
@Test
@Test
fun
isCorrect
()
{
fun
isCorrect
()
{
val
secondMax
=
findSecondMax
(
numberSet
.
numb
ers
)
val
secondMax
=
findSecondMax
(
numberSet
.
answ
ers
)
assertTrue
(
numberSet
.
isCorrect
(
secondMax
))
assertTrue
(
numberSet
.
isCorrect
(
secondMax
))
}
}
}
}
\ No newline at end of file
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