def test_equivalent_desc_have_same_representations_and_run(self): for descriptions, value, type_, text in self.known_values: chan = Channel(descriptions[0]) for desc in descriptions: chan2 = Channel(desc) chan.run(self.bits) self.assertEqual(repr(chan), repr(chan2))
def test_simple_chain_returns_correct_html(self): args_list = [ (3, 1, 0, 0), (2, 1, 0, 0), (2, 1, 0, 8), ] for args in args_list: source_number, code_number, channel_description,\ hamming_block_length = args response = simple_chain(HttpRequest(), *args) source_name, source, code_list = sources[source_number] code = code_list[code_number - 1] channel = Channel(channel_description) chain_ = Chain(source, code, channel) chain_.run() run = chain_.runs[0] expected_html = render_to_string( 'sources/chain.html', { "source": source, "source_description": urlizer.to_url(str(source)), "code": str(code), "channel": channel, "channel_description": channel.description, "hamming_block_length": hamming_block_length, "linearized_outputs": tools.colorize_and_linearize_outputs(run.outputs), "fix_source": get_fix_source(source.symbols, fix_sources) }) html = response.content.decode() self.assertEqual(remove_table_data(html), remove_table_data(expected_html)) self.assertContains(response, "hibament") self.assertContains(response, "<table") self.assertContains(response, "<tr><td>")
from django.test import TestCase from sources.views import (home, source_detail, code_stat, sources, simple_chain, general_chain, get_fix_source, fix_sources, urlizer, change_communication_system) from sources.arithmetic import views from coding import FixSource, Source, Code, Channel, Chain import coding from sources import tools from collections import OrderedDict import re source = Source([.25] * 4) code = Code("00 01 10 11") fix_source_chain = Chain(FixSource('ALABAMA'), tools.get_code('A:0 B:10 L:110 M:111'), Channel([2])) fix_source_chain.run() fix_source_run = fix_source_chain.runs[0] outputs = fix_source_run.outputs # print( # outputs, # [tools.color_diff(*[o.message for o in output]) for output in outputs], # sep='\n' # ) def remove_table_data(text): lines = text.splitlines() span = re.compile("<td>.*?</td>") new_text = [] for line in lines:
def test_verbose_description_returns_the_proper_value(self): for descriptions, value, type_, text in self.known_values: for desc in descriptions: this_channel = Channel(desc) self.assertEqual(this_channel.verbose_description(), text)
def test_intervals(self): "should have the proper representation and should be run on input" for desc in ("1/7", "1-2", "1-2/7"): # TODO to complete chan = Channel(desc) chan.run(self.bits)