Skip to content

Commit 04b1fae

Browse files
add parameterized tests
1 parent 7238c3a commit 04b1fae

16 files changed

+744
-624
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
implementation 'androidx.annotation:annotation:1.9.1'
3636
implementation 'androidx.appcompat:appcompat:1.7.0'
3737
implementation 'androidx.collection:collection-ktx:1.5.0'
38-
implementation 'androidx.core:core-ktx:1.15.0'
38+
implementation 'androidx.core:core-ktx:1.16.0'
3939
implementation 'androidx.core:core-splashscreen:1.0.1'
4040
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
4141
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7'

app/build.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Build Properties
2-
#Sun Apr 06 09:08:26 EDT 2025
3-
version_build=7
2+
#Fri Apr 11 18:01:13 EDT 2025
3+
version_build=8
44
version_major=3
55
version_minor=2
66
version_patch=0
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* WiFiAnalyzer
3+
* Copyright (C) 2015 - 2025 VREM Software Development <VREMSoftwareDevelopment@gmail.com>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>
17+
*/
18+
package com.vrem.wifianalyzer.wifi.band
19+
20+
import org.assertj.core.api.Assertions.assertThat
21+
import org.junit.Before
22+
import org.junit.Test
23+
import org.junit.runner.RunWith
24+
import org.junit.runners.Parameterized
25+
import org.junit.runners.Parameterized.Parameter
26+
import org.junit.runners.Parameterized.Parameters
27+
import java.util.Locale
28+
29+
@RunWith(Parameterized::class)
30+
class WiFiChannelCountryParameterizedTest() {
31+
private val expectedWiFiBands = listOf(
32+
WiFiBand.GHZ2 to expectedWiFiInfoGHZ2,
33+
WiFiBand.GHZ5 to expectedWiFiInfoGHZ5,
34+
WiFiBand.GHZ6 to expectedWiFiInfoGHZ6
35+
)
36+
37+
@Parameter(0)
38+
lateinit var locale: Locale
39+
40+
@Parameter(1)
41+
lateinit var countryCode: String
42+
43+
@Parameter(2)
44+
lateinit var countryName: String
45+
46+
lateinit var fixture: WiFiChannelCountry
47+
48+
@Before
49+
fun setUp() {
50+
fixture = WiFiChannelCountry(locale)
51+
}
52+
53+
@Test
54+
fun countryCode() {
55+
assertThat(fixture.countryCode).isEqualTo(countryCode)
56+
}
57+
58+
@Test
59+
fun countryName() {
60+
assertThat(fixture.countryName(Locale.US)).isEqualTo(countryName)
61+
}
62+
63+
@Test
64+
fun channels() {
65+
expectedWiFiBands.forEach { (wiFiBand, expectedWiFiInfo) ->
66+
assertThat(fixture.channels(wiFiBand))
67+
.describedAs("$wiFiBand")
68+
.containsExactlyElementsOf(expectedWiFiInfo.expectedRatingChannels(wiFiBand, countryCode))
69+
}
70+
}
71+
72+
companion object {
73+
@JvmStatic
74+
@Parameters(name = "{index}: {1} - {2}")
75+
fun data() =
76+
Locale.getAvailableLocales()
77+
.filter { !it.country.isEmpty() && !it.displayName.isEmpty() }
78+
.map { locale -> arrayOf(locale, locale.country, locale.getDisplayCountry(Locale.US)) }
79+
}
80+
}

app/src/test/kotlin/com/vrem/wifianalyzer/wifi/band/WiFiChannelCountryTest.kt

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,10 @@ package com.vrem.wifianalyzer.wifi.band
1919

2020
import com.vrem.util.allCountries
2121
import org.assertj.core.api.Assertions.assertThat
22-
import org.junit.After
23-
import org.junit.Before
2422
import org.junit.Test
2523
import java.util.Locale
2624

2725
class WiFiChannelCountryTest {
28-
private val currentLocale: Locale = Locale.getDefault()
29-
30-
private val expectedWiFiBands = listOf(
31-
WiFiBand.GHZ2 to expectedWiFiInfoGHZ2,
32-
WiFiBand.GHZ5 to expectedWiFiInfoGHZ5,
33-
WiFiBand.GHZ6 to expectedWiFiInfoGHZ6
34-
)
35-
36-
@Before
37-
fun setUp() {
38-
Locale.setDefault(Locale.US)
39-
}
40-
41-
@After
42-
fun tearDown() {
43-
Locale.setDefault(currentLocale)
44-
}
45-
46-
@Test
47-
fun fixturesCheck() {
48-
assertThat(expectedWiFiBands).hasSize(WiFiBand.entries.size)
49-
}
50-
5126
@Test
5227
fun findAll() {
5328
assertThat(WiFiChannelCountry.findAll()).hasSize(allCountries().size)
@@ -61,37 +36,4 @@ class WiFiChannelCountryTest {
6136
assertThat(actual.countryName(expected)).isEqualTo(expected.displayCountry)
6237
}
6338

64-
@Test
65-
fun countryCode() {
66-
Locale.getAvailableLocales().forEach { locale ->
67-
println("[Code: ${locale.country}]")
68-
assertThat(WiFiChannelCountry(locale).countryCode)
69-
.describedAs("Code: ${locale.country}")
70-
.isEqualTo(locale.country)
71-
}
72-
}
73-
74-
@Test
75-
fun countryName() {
76-
Locale.getAvailableLocales().forEach { locale ->
77-
println("[Code: ${locale.country}]")
78-
val fixture = WiFiChannelCountry(locale)
79-
assertThat(fixture.countryName(Locale.US))
80-
.describedAs("Code: ${locale.country}")
81-
.isEqualTo(if (locale.displayCountry.isEmpty()) "-Unknown" else locale.displayCountry)
82-
}
83-
}
84-
85-
@Test
86-
fun channels() {
87-
Locale.getAvailableLocales().forEach { locale ->
88-
val fixture = WiFiChannelCountry(locale)
89-
expectedWiFiBands.forEach { (wiFiBand, expectedWiFiInfo) ->
90-
println("[Code: ${locale.country} | $wiFiBand]")
91-
assertThat(fixture.channels(wiFiBand))
92-
.describedAs("Code: ${locale.country} | $wiFiBand")
93-
.containsExactlyElementsOf(expectedWiFiInfo.expectedRatingChannels(wiFiBand, locale.country))
94-
}
95-
}
96-
}
9739
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/*
2+
* WiFiAnalyzer
3+
* Copyright (C) 2015 - 2025 VREM Software Development <VREMSoftwareDevelopment@gmail.com>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>
17+
*/
18+
package com.vrem.wifianalyzer.wifi.band
19+
20+
import com.vrem.util.EMPTY
21+
import com.vrem.wifianalyzer.wifi.model.WiFiWidth
22+
import org.assertj.core.api.Assertions.assertThat
23+
import org.junit.runner.RunWith
24+
import org.junit.runners.Parameterized
25+
import org.junit.runners.Parameterized.Parameter
26+
import org.junit.runners.Parameterized.Parameters
27+
import kotlin.test.Test
28+
29+
@RunWith(Parameterized::class)
30+
class WiFiChannelsParameterizedTest {
31+
private val countries: List<WiFiChannelCountry> = WiFiChannelCountry.findAll()
32+
.filter { !it.locale.country.isEmpty() && !it.locale.displayName.isEmpty() }
33+
34+
@Parameter(0)
35+
lateinit var wiFiBand: WiFiBand
36+
37+
@Parameter(1)
38+
lateinit var expectedWiFiInfo: ExpectedWiFiInfo
39+
40+
@Parameter(2)
41+
lateinit var fixture: WiFiChannels
42+
43+
@Test
44+
fun inRange() {
45+
assertThat(fixture.inRange(expectedWiFiInfo.expectedChannels.first().frequency)).describedAs("$wiFiBand").isTrue()
46+
assertThat(fixture.inRange(expectedWiFiInfo.expectedChannels.last().frequency)).describedAs("$wiFiBand").isTrue()
47+
}
48+
49+
@Test
50+
fun notInRange() {
51+
assertThat(fixture.inRange(expectedWiFiInfo.expectedChannels.first().frequency - 1)).isFalse()
52+
assertThat(fixture.inRange(expectedWiFiInfo.expectedChannels.last().frequency + 1)).isFalse()
53+
}
54+
55+
@Test
56+
fun wiFiChannelByFrequencyInRange() {
57+
expectedWiFiInfo.expectedChannels.forEach { expected ->
58+
assertThat(fixture.wiFiChannelByFrequency(expected.frequency)).isEqualTo(expected)
59+
}
60+
}
61+
62+
@Test
63+
fun wiFiChannelByFrequencyOutOfRange() {
64+
assertThat(fixture.wiFiChannelByFrequency(expectedWiFiInfo.expectedChannels.first().frequency - 1)).isEqualTo(WiFiChannel.UNKNOWN)
65+
assertThat(fixture.wiFiChannelByFrequency(expectedWiFiInfo.expectedChannels.last().frequency + 1)).isEqualTo(WiFiChannel.UNKNOWN)
66+
}
67+
68+
@Test
69+
fun wiFiChannelByChannelInRange() {
70+
expectedWiFiInfo.expectedChannels.forEach { expected ->
71+
assertThat(fixture.wiFiChannelByChannel(expected.channel)).isEqualTo(expected)
72+
}
73+
}
74+
75+
@Test
76+
fun wiFiChannelByChannelNotInRange() {
77+
assertThat(fixture.wiFiChannelByChannel(expectedWiFiInfo.expectedChannels.first().channel - 1)).isEqualTo(WiFiChannel.UNKNOWN)
78+
assertThat(fixture.wiFiChannelByChannel(expectedWiFiInfo.expectedChannels.last().channel + 1)).isEqualTo(WiFiChannel.UNKNOWN)
79+
}
80+
81+
@Test
82+
fun channelRange() {
83+
assertThat(fixture.channelRange.first).isEqualTo(expectedWiFiInfo.expectedChannels.first())
84+
assertThat(fixture.channelRange.second).isEqualTo(expectedWiFiInfo.expectedChannels.last())
85+
}
86+
87+
@Test
88+
fun activeChannels() {
89+
fixture.activeChannels.forEach { (wiFiWidth, wiFiWidthChannels) ->
90+
val expected = expectedWiFiInfo.expectedActiveChannels
91+
.filter { (expectedWiFiWidth) -> expectedWiFiWidth == wiFiWidth }
92+
.map { (_, expectedWiFiWidthChannels) ->
93+
expectedWiFiWidthChannels
94+
}
95+
.first()
96+
assertThat(wiFiWidthChannels)
97+
.describedAs("$wiFiWidth")
98+
.containsExactlyElementsOf(expected)
99+
}
100+
}
101+
102+
@Test
103+
fun wiFiWidthUsingChannelInRange() {
104+
fixture.activeChannels.forEach { (wiFiWidth, channels) ->
105+
if (wiFiBand == WiFiBand.GHZ2 && wiFiWidth == WiFiWidth.MHZ_40) {
106+
return@forEach
107+
}
108+
channels.forEach { channel ->
109+
assertThat(fixture.wiFiWidthByChannel(channel))
110+
.describedAs("$wiFiWidth | Channel: $channel")
111+
.isEqualTo(wiFiWidth)
112+
}
113+
}
114+
}
115+
116+
@Test
117+
fun wiFiWidthUsingChannelNotInRange() {
118+
assertThat(fixture.wiFiWidthByChannel(wiFiBand.wiFiChannels.channelRange.first.channel - 1)).isEqualTo(WiFiWidth.MHZ_20)
119+
assertThat(fixture.wiFiWidthByChannel(wiFiBand.wiFiChannels.channelRange.second.channel + 1)).isEqualTo(WiFiWidth.MHZ_20)
120+
}
121+
122+
@Test
123+
fun availableChannels() {
124+
assertThat(fixture.availableChannels).containsExactlyElementsOf(expectedWiFiInfo.expectedAvailableChannels)
125+
}
126+
127+
@Test
128+
fun graphChannels() {
129+
assertThat(fixture.graphChannels.keys).containsExactlyElementsOf(expectedWiFiInfo.expectedGraphChannels.keys)
130+
assertThat(fixture.graphChannels.values).containsExactlyElementsOf(expectedWiFiInfo.expectedGraphChannels.values)
131+
}
132+
133+
@Test
134+
fun availableChannelsUsingWiFiBandAndCountry() {
135+
countries.forEach { country ->
136+
assertThat(fixture.availableChannels(wiFiBand, country.countryCode).map { it -> it.channel })
137+
.describedAs("Country: ${country.countryCode}")
138+
.containsExactlyElementsOf(country.channels(wiFiBand))
139+
}
140+
}
141+
142+
@Test
143+
fun availableChannelsUsingWiFiWidthWiFiBandAndCountry() {
144+
WiFiWidth.entries.forEach { wiFiWidth ->
145+
countries.forEach { country ->
146+
assertThat(fixture.availableChannels(wiFiWidth, wiFiBand, country.countryCode))
147+
.describedAs("$wiFiWidth | Country: $country")
148+
.containsExactlyElementsOf(expectedWiFiInfo.availableChannels(wiFiWidth, wiFiBand, country.countryCode))
149+
}
150+
}
151+
}
152+
153+
@Test
154+
fun ratingChannels() {
155+
countries.forEach { country ->
156+
assertThat(fixture.ratingChannels(wiFiBand, country.countryCode))
157+
.describedAs("$wiFiBand | Country: ${country.countryCode}")
158+
.containsExactlyElementsOf(expectedWiFiInfo.expectedRatingChannels(wiFiBand, country.countryCode))
159+
}
160+
}
161+
162+
@Test
163+
fun wiFiChannels() {
164+
assertThat(fixture.wiFiChannels()).containsAll(expectedWiFiInfo.expectedChannels)
165+
}
166+
167+
@Test
168+
fun graphChannelCount() {
169+
assertThat(fixture.graphChannelCount()).isEqualTo(expectedWiFiInfo.expectedChannelsCount)
170+
}
171+
172+
@Test
173+
fun graphChannelByFrequencyInRange() {
174+
expectedWiFiInfo.expectedChannels.forEach { (channel, frequency) ->
175+
assertThat(fixture.graphChannelByFrequency(frequency))
176+
.describedAs("Channel: $channel | Frequency: $frequency")
177+
.isEqualTo(expectedWiFiInfo.expectedGraphChannels[channel] ?: String.EMPTY)
178+
}
179+
}
180+
181+
@Test
182+
fun graphChannelByFrequencyOutOfRange() {
183+
assertThat(fixture.graphChannelByFrequency(expectedWiFiInfo.expectedChannels.first().frequency - 1)).isEmpty()
184+
assertThat(fixture.graphChannelByFrequency(expectedWiFiInfo.expectedChannels.last().frequency + 1)).isEmpty()
185+
}
186+
187+
companion object {
188+
@JvmStatic
189+
@Parameters(name = "{0}")
190+
fun data() = listOf(
191+
arrayOf(WiFiBand.GHZ2, expectedWiFiInfoGHZ2, wiFiChannelsGHZ2),
192+
arrayOf(WiFiBand.GHZ5, expectedWiFiInfoGHZ5, wiFiChannelsGHZ5),
193+
arrayOf(WiFiBand.GHZ6, expectedWiFiInfoGHZ6, wiFiChannelsGHZ6)
194+
)
195+
}
196+
197+
}

0 commit comments

Comments
 (0)