Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.vrem.wifianalyzer.wifi.graphutils.MAX_SCAN_COUNT
import com.vrem.wifianalyzer.wifi.graphutils.MIN_Y
import com.vrem.wifianalyzer.wifi.graphutils.MIN_Y_OFFSET
import com.vrem.wifianalyzer.wifi.model.WiFiDetail
import com.vrem.wifianalyzer.wifi.predicate.Predicate

@OpenClass
internal class DataManager(
Expand All @@ -37,34 +38,42 @@ internal class DataManager(
graphViewWrapper: GraphViewWrapper,
wiFiDetails: List<WiFiDetail>,
levelMax: Int,
predicate: Predicate,
): Set<WiFiDetail> {
val inOrder: Set<WiFiDetail> = wiFiDetails.toSet()
inOrder.forEach { addData(graphViewWrapper, it, levelMax) }
adjustData(graphViewWrapper, inOrder)
adjustData(graphViewWrapper, inOrder, predicate)
xValue++
if (scanCount < MAX_SCAN_COUNT) {
scanCount++
}
if (scanCount == 2) {
graphViewWrapper.setHorizontalLabelsVisible(true)
}
return newSeries(inOrder)
return newSeries(inOrder, predicate)
}

fun adjustData(
graphViewWrapper: GraphViewWrapper,
wiFiDetails: Set<WiFiDetail>,
predicate: Predicate,
) {
graphViewWrapper.differenceSeries(wiFiDetails).forEach {
val dataPoint = GraphDataPoint(xValue, MIN_Y + MIN_Y_OFFSET)
val drawBackground = it.wiFiAdditional.wiFiConnection.connected
graphViewWrapper.appendToSeries(it, dataPoint, scanCount, drawBackground)
timeGraphCache.add(it)
}
graphViewWrapper
.differenceSeries(wiFiDetails)
.filter { predicate(it) }
.forEach {
val dataPoint = GraphDataPoint(xValue, MIN_Y + MIN_Y_OFFSET)
val drawBackground = it.wiFiAdditional.wiFiConnection.connected
graphViewWrapper.appendToSeries(it, dataPoint, scanCount, drawBackground)
timeGraphCache.add(it)
}
timeGraphCache.clear()
}

fun newSeries(wiFiDetails: Set<WiFiDetail>): Set<WiFiDetail> = wiFiDetails.plus(timeGraphCache.active())
fun newSeries(
wiFiDetails: Set<WiFiDetail>,
predicate: Predicate,
): Set<WiFiDetail> = wiFiDetails.plus(timeGraphCache.active().filter { predicate(it) })

fun addData(
graphViewWrapper: GraphViewWrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ internal class TimeGraphView(
graphViewWrapper,
wiFiDetails,
MainContext.INSTANCE.settings.graphMaximumY(),
predicate,
)
graphViewWrapper.removeSeries(newSeries)
graphViewWrapper.updateLegend(MainContext.INSTANCE.settings.timeGraphLegend())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import com.vrem.wifianalyzer.wifi.model.WiFiIdentifier
import com.vrem.wifianalyzer.wifi.model.WiFiSecurity
import com.vrem.wifianalyzer.wifi.model.WiFiSignal
import com.vrem.wifianalyzer.wifi.model.WiFiWidth
import com.vrem.wifianalyzer.wifi.predicate.falsePredicate
import com.vrem.wifianalyzer.wifi.predicate.truePredicate
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -59,7 +61,7 @@ class DataManagerTest {
// setup
assertThat(fixture.xValue).isEqualTo(0)
// execute
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
// validate
assertThat(fixture.xValue).isEqualTo(1)
}
Expand All @@ -69,7 +71,7 @@ class DataManagerTest {
// setup
assertThat(fixture.scanCount).isEqualTo(0)
// execute
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
// validate
assertThat(fixture.scanCount).isEqualTo(1)
}
Expand All @@ -80,7 +82,7 @@ class DataManagerTest {
val wiFiDetails = makeWiFiDetails()
val wiFiDetailsSet = wiFiDetails.toSet()
// execute
fixture.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y)
fixture.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y, truePredicate)
// validate
wiFiDetailsSet.forEach {
verify(graphViewWrapper).newSeries(it)
Expand All @@ -93,7 +95,7 @@ class DataManagerTest {
// setup
fixture.scanCount = MAX_SCAN_COUNT
// execute
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
// validate
assertThat(fixture.scanCount).isEqualTo(MAX_SCAN_COUNT)
}
Expand All @@ -103,7 +105,7 @@ class DataManagerTest {
// setup
fixture.scanCount = 1
// execute
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
// validate
assertThat(fixture.scanCount).isEqualTo(2)
verify(graphViewWrapper).setHorizontalLabelsVisible(true)
Expand All @@ -112,7 +114,7 @@ class DataManagerTest {
@Test
fun addSeriesDoesNotSetHorizontalLabelsVisible() {
// execute
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
// validate
verify(graphViewWrapper, never()).setHorizontalLabelsVisible(true)
}
Expand All @@ -127,7 +129,7 @@ class DataManagerTest {
val dataPoint = GraphDataPoint(xValue, MIN_Y + MIN_Y_OFFSET)
whenever(graphViewWrapper.differenceSeries(wiFiDetails)).thenReturn(difference)
// execute
fixture.adjustData(graphViewWrapper, wiFiDetails)
fixture.adjustData(graphViewWrapper, wiFiDetails, truePredicate)
// validate
difference.forEach {
verify(graphViewWrapper).appendToSeries(
Expand All @@ -148,13 +150,52 @@ class DataManagerTest {
val moreWiFiDetails: Set<WiFiDetail> = makeMoreWiFiDetails().toSet()
whenever(timeGraphCache.active()).thenReturn(moreWiFiDetails)
// execute
val actual = fixture.newSeries(wiFiDetails)
val actual = fixture.newSeries(wiFiDetails, truePredicate)
// validate
assertThat(actual).containsAll(wiFiDetails)
assertThat(actual).containsAll(moreWiFiDetails)
verify(timeGraphCache).active()
}

@Test
fun newSeriesShouldNotIncludeActiveCacheEntriesNotInCurrentWiFiDetails() {
// Expected: newSeries includes currentDetails and only those active cache
// entries that satisfy the given predicate. Entries from timeGraphCache.active()
// that do not match the predicate (e.g. filtered-out SSIDs) must be excluded.
// setup
val currentDetails: Set<WiFiDetail> = makeWiFiDetails().toSet()
val staleEntries: Set<WiFiDetail> = makeMoreWiFiDetails().toSet()
whenever(timeGraphCache.active()).thenReturn(staleEntries)
// execute
val actual = fixture.newSeries(currentDetails, falsePredicate)
assertThat(actual).containsAll(currentDetails)
assertThat(actual).doesNotContainAnyElementsOf(staleEntries)
verify(timeGraphCache).active()
}

@Test
fun adjustDataShouldNotAppendToStaleCacheEntriesNotInCurrentDetails() {
// Expected: adjustData only appends floor data points and increments the
// TimeGraphCache counter for differenceSeries entries that satisfy the
// given predicate. Entries that do not match must be left untouched.
// setup
val currentDetails: Set<WiFiDetail> = makeWiFiDetails().toSet()
val staleEntry: WiFiDetail = makeWiFiDetail("SSID4")
whenever(graphViewWrapper.differenceSeries(currentDetails))
.thenReturn(listOf(staleEntry))
// execute
fixture.adjustData(graphViewWrapper, currentDetails, falsePredicate)
verify(graphViewWrapper, never()).appendToSeries(
eq(staleEntry),
any(),
any(),
any(),
)
// validate: stale entries must NOT be added to the time graph cache
verify(timeGraphCache, never()).add(staleEntry)
verify(timeGraphCache).clear()
}

@Test
fun addDataToExistingSeries() {
// setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TimeGraphViewTest {
val wiFiData = WiFiData(wiFiDetails, WiFiConnection.EMPTY)
val predicate: Predicate = truePredicate
doReturn(predicate).whenever(fixture).predicate(settings)
whenever(dataManager.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y)).thenReturn(newSeries)
whenever(dataManager.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y, predicate)).thenReturn(newSeries)
whenever(settings.sortBy()).thenReturn(SortBy.SSID)
whenever(settings.timeGraphLegend()).thenReturn(GraphLegend.LEFT)
whenever(settings.wiFiBand()).thenReturn(WiFiBand.GHZ2)
Expand All @@ -80,7 +80,7 @@ class TimeGraphViewTest {
fixture.update(wiFiData)
// validate
verify(fixture).predicate(settings)
verify(dataManager).addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y)
verify(dataManager).addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y, predicate)
verify(graphViewWrapper).removeSeries(newSeries)
verify(graphViewWrapper).updateLegend(GraphLegend.LEFT)
verify(graphViewWrapper).visibility(View.VISIBLE)
Expand Down
Loading