# Path: lpdec/channels.py
# class Channel(JSONDecodable):
# class AWGNC(Channel):
# class BSC(Channel):
# class SignalGenerator(object):
#     def __init__(self, seed=None, q=2):
#     def resetSeed(self):
#     def modulate(self, codeword):
#     def simulate(self, codeword):
#     def skip(self, word, num):
#     def __call__(self, codeword):
#     def signalGenerator(self, code, **kwargs):
#     def __init__(self, snr, coderate, q=2, round=None, seed=None):
#     def simulate(self, codeword):
#     def skip(self, word, num):
#     def params(self):
#     def __init__(self, p, seed=None):
#     def simulate(self, codeword):
#     def params(self):
#     def __init__(self, code, channel, wordSeed=None):
#     def __iter__(self):
#     def next(self):
#     def skip(self, num):
#     def __next__(self):
#     def correctObjectiveValue(self):
#             N0 = 1 / (coderate * 10 ** (snr / 10))


import unittest
import numpy as np
from lpdec import channels
    def setUp(self):
        np.random.seed(self.inputSeed)
        self.p = .5*np.random.random()
        self.channel = channels.BSC(self.p, self.channelSeed)

    def testRandomBSC(self):
        TRIALS = 10000
        totals = flips = 0
        for i in range(TRIALS):
            # generate random BPSK vector of random size between 10 and 100
            input = np.random.randint(0, 2, np.random.randint(10, 100))
            totals += input.size
            output = self.channel(input)
            self.assertEqual(input.shape, output.shape)
            flips += np.sum(1-2*input != np.sign(output))
        self.assertAlmostEqual(self.p, flips / totals, 2)

    def testAllzeroBSC(self):
        TRIALS = 10000
        flips = 0
        totals = 0
        for i in range(TRIALS):
            input = np.zeros(np.random.randint(10, 100))  # generate random-length zero-codeword
            totals += input.size
            output = self.channel(input)
            self.assertEqual(input.shape, output.shape)
            flips += np.sum(output < 0)
        self.assertAlmostEqual(self.p, flips / totals, 2)

    def testSeed(self):

# Path: lpdec/channels.py
# class Channel(JSONDecodable):
# class AWGNC(Channel):
# class BSC(Channel):
# class SignalGenerator(object):
#     def __init__(self, seed=None, q=2):
#     def resetSeed(self):
#     def modulate(self, codeword):
#     def simulate(self, codeword):
#     def skip(self, word, num):
#     def __call__(self, codeword):
#     def signalGenerator(self, code, **kwargs):
#     def __init__(self, snr, coderate, q=2, round=None, seed=None):
#     def simulate(self, codeword):
#     def skip(self, word, num):
#     def params(self):
#     def __init__(self, p, seed=None):
#     def simulate(self, codeword):
#     def params(self):
#     def __init__(self, code, channel, wordSeed=None):
#     def __iter__(self):
#     def next(self):
#     def skip(self, num):
#     def __next__(self):
#     def correctObjectiveValue(self):
#             N0 = 1 / (coderate * 10 ** (snr / 10))


# Path: test/test_channels.py
import unittest
import numpy as np
from lpdec import channels

    def setUp(self):
        np.random.seed(self.inputSeed)
        self.p = .5*np.random.random()
        self.channel = channels.BSC(self.p, self.channelSeed)

    def testRandomBSC(self):
        TRIALS = 10000
        totals = flips = 0
        for i in range(TRIALS):
            # generate random BPSK vector of random size between 10 and 100
            input = np.random.randint(0, 2, np.random.randint(10, 100))
            totals += input.size
            output = self.channel(input)
            self.assertEqual(input.shape, output.shape)
            flips += np.sum(1-2*input != np.sign(output))
        self.assertAlmostEqual(self.p, flips / totals, 2)

    def testAllzeroBSC(self):
        TRIALS = 10000
        flips = 0
        totals = 0
        for i in range(TRIALS):
            input = np.zeros(np.random.randint(10, 100))  # generate random-length zero-codeword
            totals += input.size
            output = self.channel(input)
            self.assertEqual(input.shape, output.shape)
            flips += np.sum(output < 0)
        self.assertAlmostEqual(self.p, flips / totals, 2)

    def testSeed(self):

        channel2 = channels.BSC(self.p, self.channelSeed)