Coverage for test/d7a/phy/test_subband.py: 100%

50 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-24 08:03 +0200

1# 

2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV. 

3# 

4# This file is part of pyd7a. 

5# See https://github.com/Sub-IoT/pyd7a for further info. 

6# 

7# Licensed under the Apache License, Version 2.0 (the "License"); 

8# you may not use this file except in compliance with the License. 

9# You may obtain a copy of the License at 

10# 

11# http://www.apache.org/licenses/LICENSE-2.0 

12# 

13# Unless required by applicable law or agreed to in writing, software 

14# distributed under the License is distributed on an "AS IS" BASIS, 

15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

16# See the License for the specific language governing permissions and 

17# limitations under the License. 

18# 

19import unittest 

20 

21from bitstring import ConstBitStream 

22from d7a.phy.subband import SubBand 

23 

24 

25class TestSubband(unittest.TestCase): 

26 def test_default_ctor(self): 

27 sb = SubBand() 

28 self.assertEqual(sb.channel_index_start, 0) 

29 self.assertEqual(sb.channel_index_end, 0) 

30 self.assertEqual(sb.eirp, 0) 

31 self.assertEqual(sb.cca, 86) 

32 self.assertEqual(sb.duty, 255) 

33 

34 def test_validation_ok(self): 

35 sb = SubBand(channel_index_start=0, 

36 channel_index_end=0, 

37 eirp=10, 

38 cca=86, 

39 duty=10) 

40 

41 def test_validation_channel_index_start(self): 

42 def bad(): sb = SubBand(channel_index_start=-10) 

43 self.assertRaises(ValueError, bad) 

44 

45 

46 def test_validation_channel_index_end(self): 

47 def bad(): sb = SubBand(channel_index_end=-10) 

48 self.assertRaises(ValueError, bad) 

49 

50 def test_validation_eirp(self): 

51 def bad(): sb = SubBand(eirp=200) 

52 self.assertRaises(ValueError, bad) 

53 

54 def test_validation_cca(self): 

55 def bad(): sb = SubBand(cca=-10) 

56 self.assertRaises(ValueError, bad) 

57 

58 def test_validation_duty(self): 

59 def bad(): sb = SubBand(duty=500) 

60 self.assertRaises(ValueError, bad) 

61 

62 

63 def test_byte_generation(self): 

64 expected = [ 

65 0, 0, # channel index start 

66 0, 16, # channel index end 

67 10, # eirp 

68 86, # ccao 

69 255 # duty 

70 ] 

71 sb = SubBand(channel_index_start=0, 

72 channel_index_end=16, 

73 eirp=10, 

74 cca=86, 

75 duty=255) 

76 bytes = bytearray(sb) 

77 for i in range(len(bytes)): 

78 self.assertEqual(expected[i], bytes[i]) 

79 

80 self.assertEqual(len(expected), len(bytes)) 

81 

82 

83 def test_byte_generation_neg_eirp(self): 

84 expected = [ 

85 0, 0, # channel index start 

86 0, 16, # channel index end 

87 0xF6, # eirp 

88 86, # ccao 

89 255 # duty 

90 ] 

91 sb = SubBand(channel_index_start=0, 

92 channel_index_end=16, 

93 eirp=-10, 

94 cca=86, 

95 duty=255) 

96 bytes = bytearray(sb) 

97 for i in range(len(bytes)): 

98 self.assertEqual(expected[i], bytes[i]) 

99 

100 self.assertEqual(len(expected), len(bytes)) 

101 

102 def test_parse_neg_eirp(self): 

103 bytes = [ 

104 0, 0, # channel index start 

105 0, 16, # channel index end 

106 0xF6, # eirp 

107 86, # ccao 

108 255 # duty 

109 ] 

110 

111 sb = SubBand.parse(ConstBitStream(bytes=bytes)) 

112 self.assertEqual(sb.channel_index_start, 0) 

113 self.assertEqual(sb.channel_index_end, 16) 

114 self.assertEqual(sb.eirp, -10) 

115 self.assertEqual(sb.cca, 86) 

116 self.assertEqual(sb.duty, 255)