Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2020 The Magma Authors. |
| 3 | |
| 4 | This source code is licensed under the BSD-style license found in the |
| 5 | LICENSE file in the root directory of this source tree. |
| 6 | |
| 7 | Unless required by applicable law or agreed to in writing, software |
| 8 | distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | See the License for the specific language governing permissions and |
| 11 | limitations under the License. |
| 12 | """ |
| 13 | |
| 14 | # pylint: disable=protected-access |
| 15 | from unittest import TestCase |
| 16 | |
| 17 | from data_models.transform_for_magma import bandwidth, gps_tr181 |
| 18 | from exceptions import ConfigurationError |
| 19 | |
| 20 | |
| 21 | class TransformForMagmaTests(TestCase): |
| 22 | def test_gps_tr181(self) -> None: |
| 23 | # Negative longitude |
| 24 | inp = '-122150583' |
| 25 | out = gps_tr181(inp) |
| 26 | expected = '-122.150583' |
| 27 | self.assertEqual(out, expected, 'Should convert negative longitude') |
| 28 | |
| 29 | inp = '122150583' |
| 30 | out = gps_tr181(inp) |
| 31 | expected = '122.150583' |
| 32 | self.assertEqual(out, expected, 'Should convert positive longitude') |
| 33 | |
| 34 | inp = '0' |
| 35 | out = gps_tr181(inp) |
| 36 | expected = '0.0' |
| 37 | self.assertEqual(out, expected, 'Should leave zero as zero') |
| 38 | |
| 39 | def test_bandwidth(self) -> None: |
| 40 | inp = 'n6' |
| 41 | out = bandwidth(inp) |
| 42 | expected = 1.4 |
| 43 | self.assertEqual(out, expected, 'Should convert RBs') |
| 44 | |
| 45 | inp = 1.4 |
| 46 | out = bandwidth(inp) |
| 47 | expected = 1.4 |
| 48 | self.assertEqual(out, expected, 'Should accept MHz') |
| 49 | |
| 50 | with self.assertRaises(ConfigurationError): |
| 51 | inp = 'asdf' |
| 52 | bandwidth(inp) |
| 53 | |
| 54 | with self.assertRaises(ConfigurationError): |
| 55 | inp = 1234 |
| 56 | bandwidth(inp) |