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
Hide 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
class
MainActivityTest
{
@get
:
Rule
val
testRule
=
ActivityTestRule
<
MainActivity
>(
MainActivity
::
class
.
java
)
private
lateinit
var
radioGroup
:
RadioGroup
//
private lateinit var radioGroup: RadioGroup
@Before
fun
init
()
{
radioGroup
=
testRule
.
activity
.
radio_group
//
radioGroup = testRule.activity.radio_group
}
@Test
...
...
app/src/main/java/com/example/quickmax/AnswerSet.kt
View file @
0888956b
...
...
@@ -3,21 +3,26 @@ package com.example.quickmax
class
AnswerSet
(
numDigits
:
Int
):
Iterable
<
Answer
>
{
private
val
buttonIds
=
listOf
(
R
.
id
.
btn_left_top
,
R
.
id
.
btn_right_top
,
R
.
id
.
btn_left_bottom
,
R
.
id
.
btn_right_bottom
)
private
val
numOptions
=
4
val
numbers
:
MutableList
<
Answer
>
=
MutableList
(
numOptions
)
{
i
->
Answer
(
buttonIds
[
i
],
generateRandom
(
numDigits
))
}
val
buttonIds
=
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
lateinit
var
correctAnswer
:
Answer
val
answers
:
MutableList
<
Answer
>
=
mutableListOf
()
init
{
val
correctAnswer
=
findSecondMax
(
numbers
.
map
{
n
->
n
.
value
})
numbers
.
forEach
{
n
->
n
.
correct
=
n
.
value
==
correctAnswer
val
randomNumbers
=
generateNRandomNumbers
(
numDigits
,
numAnswers
)
for
(
i
in
0
until
numAnswers
)
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
>
{
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 {
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
{
var
firstMax
=
0
var
secondMax
=
0
...
...
app/src/test/java/com/example/quickmax/AnswerSetTest.kt
View file @
0888956b
...
...
@@ -12,13 +12,13 @@ class AnswerSetTest {
@Test
fun
test_constructor
()
{
assertEquals
(
numOptions
,
numberSet
.
numb
ers
.
size
)
numberSet
.
numb
ers
.
forEach
{
n
->
n
in
(
100
..
999
)
}
assertEquals
(
numOptions
,
numberSet
.
answ
ers
.
size
)
numberSet
.
answ
ers
.
forEach
{
n
->
n
in
(
100
..
999
)
}
}
@Test
fun
isCorrect
()
{
val
secondMax
=
findSecondMax
(
numberSet
.
numb
ers
)
val
secondMax
=
findSecondMax
(
numberSet
.
answ
ers
)
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