|
| 1 | +/* |
| 2 | + * This source file forms part of DENGR, a piece of software which |
| 3 | + * produces disc images which produce visible images on the recording side when |
| 4 | + * burned to Compact Disc. |
| 5 | + * |
| 6 | + * Copyright (C) 2020 Joshua Saxby <[email protected]> |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License as published |
| 10 | + * by the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + */ |
| 21 | +#include <tuple> |
| 22 | + |
| 23 | +#include <cstddef> |
| 24 | + |
| 25 | +#include "../vendor/catch.hpp" |
| 26 | + |
| 27 | +#include "../dengr/ChannelBit.hpp" |
| 28 | +#include "../dengr/Pit.hpp" |
| 29 | +#include "../dengr/physical_layer.hpp" |
| 30 | + |
| 31 | + |
| 32 | +using namespace com::saxbophone::dengr; |
| 33 | +using namespace com::saxbophone::dengr::physical_layer; |
| 34 | + |
| 35 | +SCENARIO("Sequences of bits can be converted to/from sequences of pits/lands") { |
| 36 | + const std::size_t LENGTH = 8; |
| 37 | + // convenience typedef to keep the test case data lines within limits |
| 38 | + typedef std::tuple<Pit, std::uint8_t, std::uint8_t> TestData; |
| 39 | + // bits are stuffed into uints here for compactness |
| 40 | + auto bits_pits_combination = GENERATE( |
| 41 | + // previous-pit bits pits |
| 42 | + TestData(Pit::LAND, 0b01101001, 0b01001110), |
| 43 | + TestData(Pit::PIT , 0b01101001, 0b10110001), |
| 44 | + TestData(Pit::LAND, 0b11101010, 0b10110011), |
| 45 | + TestData(Pit::PIT , 0b00110011, 0b11011101), |
| 46 | + TestData(Pit::PIT , 0b00100100, 0b11000111), |
| 47 | + TestData(Pit::LAND, 0b00010000, 0b00011111), |
| 48 | + TestData(Pit::LAND, 0b11001101, 0b10001001), |
| 49 | + TestData(Pit::PIT , 0b11110111, 0b01011010), |
| 50 | + TestData(Pit::LAND, 0b10010010, 0b11100011), |
| 51 | + TestData(Pit::PIT , 0b00010010, 0b11100011), |
| 52 | + TestData(Pit::PIT , 0b10000000, 0b00000000), |
| 53 | + TestData(Pit::LAND, 0b00000000, 0b00000000) |
| 54 | + ); |
| 55 | + // extract the bit patterns for use in the test case |
| 56 | + ChannelBitArray<LENGTH> bits; |
| 57 | + PitArray<LENGTH> pits; |
| 58 | + // also extract the previous pit value |
| 59 | + Pit previous_pit = std::get<0>(bits_pits_combination); |
| 60 | + for (std::uint8_t i = 0; i < 8; i++) { |
| 61 | + bits[i] = (std::get<1>(bits_pits_combination) & (1 << (7 - i))) != 0; |
| 62 | + pits[i] = (Pit)((std::get<2>(bits_pits_combination) & (1 << (7 - i))) != 0); |
| 63 | + } |
| 64 | + |
| 65 | + GIVEN("A sequence of Channel Bits and its corresponding sequence of pits/lands") { |
| 66 | + WHEN("The bits are passed into the pit/land encoder") { |
| 67 | + PitArray<LENGTH> output = bits_to_pits(previous_pit, bits); |
| 68 | + THEN("The encoder should return a corresponding sequence of pits/lands") { |
| 69 | + // output should be equal to pits, which is what's expected |
| 70 | + REQUIRE(output == pits); |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + GIVEN("A sequence of pits/lands and its corresponding sequence of Channel Bits") { |
| 76 | + WHEN("The pits/lands are passed into the pit/land decoder") { |
| 77 | + ChannelBitArray<LENGTH> output = pits_to_bits(previous_pit, pits); |
| 78 | + THEN("The decoder should return a corresponding sequence of bits") { |
| 79 | + // output should be equal to bits, which is what's expected |
| 80 | + REQUIRE(output == bits); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments