Skip to content

Commit 44630d2

Browse files
add missing tests
1 parent 1405d2e commit 44630d2

File tree

7 files changed

+31
-14
lines changed

7 files changed

+31
-14
lines changed

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-
#Tue Mar 25 22:01:30 EDT 2025
3-
version_build=10
2+
#Tue Mar 25 22:38:45 EDT 2025
3+
version_build=11
44
version_major=3
55
version_minor=1
66
version_patch=4

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/band/WiFiChannelCountryGHZ2.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import java.util.SortedSet
2323

2424
internal class WiFiChannelCountryGHZ2 {
2525
private val countries = setOf("AS", "CA", "CO", "DO", "FM", "GT", "GU", "MP", "MX", "PA", "PR", "UM", "US", "UZ", "VI")
26-
private val channels = sortedSetOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
27-
private val world = channels.union(setOf(12, 13)).toSortedSet()
26+
private val channels = (1..11).toSortedSet()
27+
private val world = channels.union((12..13).toSet()).toSortedSet()
2828

2929
fun findChannels(countryCode: String): SortedSet<Int> =
3030
if (countries.contains(countryCode.toCapitalize(Locale.getDefault()))) channels else world

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/band/WiFiChannels.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ abstract class WiFiChannels(val channelRange: WiFiChannelPair, val graphChannels
4848

4949
fun graphChannelByFrequency(frequency: Int): String {
5050
val wiFiChannel: WiFiChannel = wiFiChannelByFrequency(frequency)
51-
return if (WiFiChannel.UNKNOWN == wiFiChannel) {
52-
String.EMPTY
51+
return if (WiFiChannel.UNKNOWN != wiFiChannel && graphChannels.contains(wiFiChannel.channel)) {
52+
"${wiFiChannel.channel}"
5353
} else {
54-
if (graphChannels.contains(wiFiChannel.channel)) "${wiFiChannel.channel}" else String.EMPTY
54+
String.EMPTY
5555
}
5656
}
5757

@@ -60,10 +60,9 @@ abstract class WiFiChannels(val channelRange: WiFiChannelPair, val graphChannels
6060
fun wiFiChannels(): List<WiFiChannel> = (channelRange.first.channel..channelRange.second.channel).map { wiFiChannelByChannel(it) }
6161

6262
private fun wiFiChannel(frequency: Int, wiFiChannelPair: WiFiChannelPair): WiFiChannel {
63-
val (first, last) = wiFiChannelPair
64-
val firstChannel: Int = (first.channel + if (first.channel < 0) -0.5 else 0.5).toInt()
65-
val channel: Int = ((frequency - first.frequency).toDouble() / FREQUENCY_SPREAD + firstChannel).toInt()
66-
return if (frequency in first.frequency..last.frequency) WiFiChannel(channel, frequency) else WiFiChannel.UNKNOWN
63+
val firstChannel: Int = (wiFiChannelPair.first.channel + if (wiFiChannelPair.first.channel < 0) -0.5 else 0.5).toInt()
64+
val channel: Int = ((frequency - wiFiChannelPair.first.frequency).toDouble() / FREQUENCY_SPREAD + firstChannel).toInt()
65+
return WiFiChannel(channel, frequency)
6766
}
6867

6968
companion object {

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/band/WiFiChannelsGHZ6.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class WiFiChannelsGHZ6 : WiFiChannels(channelRange, graphChannels) {
2929
}
3030

3131
companion object {
32-
private val channelRange = WiFiChannelPair(WiFiChannel(-1, 5945), WiFiChannel(235, 7125))
32+
private val channelRange = WiFiChannelPair(WiFiChannel(-5, 5925), WiFiChannel(235, 7125))
3333
private val graphChannels: Set<Int> = setOf(15, 47, 79, 110, 142, 174, 208)
3434
}
3535

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class WiFiChannelsGHZ2Test {
103103
}
104104

105105
@Test
106-
fun graphChannelByFrequency() {
106+
fun graphChannelByFrequencyInRange() {
107107
expectedChannels.forEach { it ->
108108
// setup
109109
val expected = if (expectedGraphChannels.contains(it.channel)) "${it.channel}" else String.EMPTY
@@ -114,4 +114,10 @@ class WiFiChannelsGHZ2Test {
114114
}
115115
}
116116

117+
@Test
118+
fun graphChannelByFrequencyOutInRange() {
119+
assertThat(fixture.graphChannelByFrequency(expectedChannels.first().frequency - 1)).isEmpty()
120+
assertThat(fixture.graphChannelByFrequency(expectedChannels.last().frequency + 1)).isEmpty()
121+
}
122+
117123
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,10 @@ class WiFiChannelsGHZ5Test {
115115
}
116116
}
117117

118+
@Test
119+
fun graphChannelByFrequencyOutInRange() {
120+
assertThat(fixture.graphChannelByFrequency(expectedChannels.first().frequency - 1)).isEmpty()
121+
assertThat(fixture.graphChannelByFrequency(expectedChannels.last().frequency + 1)).isEmpty()
122+
}
123+
118124
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.junit.Test
2424
import java.util.Locale
2525

2626
class WiFiChannelsGHZ6Test {
27-
private val expectedChannels: List<WiFiChannel> = (-1..235).map { WiFiChannel(it, 5950 + it * FREQUENCY_SPREAD) }
27+
private val expectedChannels: List<WiFiChannel> = (-5..235).map { WiFiChannel(it, 5950 + it * FREQUENCY_SPREAD) }
2828
private val expectedGraphChannels = listOf(15, 47, 79, 110, 142, 174, 208)
2929
private val fixture: WiFiChannelsGHZ6 = WiFiChannelsGHZ6()
3030

@@ -114,4 +114,10 @@ class WiFiChannelsGHZ6Test {
114114
}
115115
}
116116

117+
@Test
118+
fun graphChannelByFrequencyOutInRange() {
119+
assertThat(fixture.graphChannelByFrequency(expectedChannels.first().frequency - 1)).isEmpty()
120+
assertThat(fixture.graphChannelByFrequency(expectedChannels.last().frequency + 1)).isEmpty()
121+
}
122+
117123
}

0 commit comments

Comments
 (0)