File tree Expand file tree Collapse file tree
androidTest/kotlin/app/nubrick/nubrick/data/database
main/kotlin/app/nubrick/nubrick/data/database Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package app.nubrick.nubrick.data.database
22
3+ import android.database.sqlite.SQLiteDatabase
4+ import app.nubrick.nubrick.schema.ConditionOperator
5+ import app.nubrick.nubrick.schema.FrequencyUnit
6+ import app.nubrick.nubrick.schema.UserEventFrequencyCondition
37import org.junit.Assert
8+ import org.junit.After
9+ import org.junit.Before
410import org.junit.Test
511
6- class ExampleUnitTest {
12+ class DatabaseRepositoryAndroidTest {
13+ private lateinit var db: SQLiteDatabase
14+ private lateinit var repository: DatabaseRepositoryImpl
15+
16+ @Before
17+ fun setUp () {
18+ db = SQLiteDatabase .create(null )
19+ db.execSQL(SQL_CREATE_EXPERIMENT_HISTORY_TABLE )
20+ db.execSQL(SQL_CREATE_USER_EVENT_TABLE )
21+ repository = DatabaseRepositoryImpl (db)
22+ }
23+
24+ @After
25+ fun tearDown () {
26+ db.close()
27+ }
28+
729 @Test
8- fun addition_isCorrect () {
9- Assert .assertEquals(4 , 2 + 2 )
30+ fun eventFrequencyConditionCountsEventsInSameBucket () {
31+ repository.appendUserEvent(" purchase" )
32+ repository.appendUserEvent(" purchase" )
33+
34+ val matched = repository.isMatchedToUserEventFrequencyCondition(
35+ UserEventFrequencyCondition (
36+ eventName = " purchase" ,
37+ lookbackPeriod = 1 ,
38+ unit = FrequencyUnit .DAY ,
39+ comparison = ConditionOperator .GreaterThanOrEqual ,
40+ threshold = 2 ,
41+ )
42+ )
43+
44+ Assert .assertTrue(matched)
1045 }
1146}
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ internal class DatabaseRepositoryImpl(private val db: SQLiteDatabase): DatabaseR
7878 lookbackPeriod = condition.lookbackPeriod,
7979 since = condition.since
8080 )
81- val total = counts.values.count ()
81+ val total = counts.values.sum ()
8282 return compareInteger(total, listOf (threshold), comparison)
8383 }
84- }
84+ }
You can’t perform that action at this time.
0 commit comments