def store_test(): analyzer = Analyzer() analyzer.feed_from_raw_file(SAMPLE_RAW_FILENAME) analyzer.store(TEST_EXPORT_FILENAME) assert files_equal(TEST_EXPORT_FILENAME, SAMPLE_EXPORT_FILENAME)
def discard_test(): analyzer = Analyzer("aaaaaaaaabbbcccd") assert analyzer.score("a") > 0 analyzer.discard("bcd") assert analyzer.score("a") == 0 analyzer = Analyzer("abcde") assert analyzer.score("dedede") > 0 analyzer.discard(["a", "b", "c"]) assert analyzer.score("dedede") == 0
def main(): patterns = sys.argv[1:] files = get_files_matching_patterns(patterns) analyzer = Analyzer() for raw_file in files: analyzer.feed_from_raw_file(raw_file) print analyzer.serialize()
def feed_from_raw_file_test(): analyzer = Analyzer() analyzer.feed_from_raw_file(SAMPLE_RAW_FILENAME) target = "Doth mother know you weareth her drapes?" answer = analyzer.choose_best([ target, "aergarg arogargath argnhotbno agrepaignar", "argoarg atobhhola qoqrgn gr" ]) assert answer[0] == "Doth mother know you weareth her drapes?"
def score_analyzer_test(): analyzer = Analyzer() analyzer.feed("aaabbc") assert analyzer.score("cabbaa") == 0 assert analyzer.score("aaaaaaa") == 0.25 + 1. / 9 + 1. / 36 # unicode works just fine assert analyzer.score(u"😁😒·$aaaa") == 4. / 64 + 1. / 9 + 1. / 36
def transform_keys_test(): analyzer = Analyzer("AAaaaa") assert analyzer.score("Aaa") == 0 analyzer.transform_keys(lambda s: s.upper()) assert analyzer.score("Aaa") > 0 assert analyzer.score("A") == 0
def choose_best_test(): analyzer = Analyzer() analyzer.feed("aaabbc") strings = [ "babcaa", "cd", "bbbbbddd", "aaaaaaaaaaaaddd" ] answers = analyzer.choose_best(strings, 4) assert answers[0] == strings[0] assert answers[1] == strings[3] assert answers[2] == strings[2] assert answers[3] == strings[1] answer = analyzer.choose_best(strings) assert len(answer) == 1 assert answers[0] == strings[0]
def score_analyzer_test(): analyzer = Analyzer() analyzer.feed("aaabbc") assert analyzer.score("cabbaa") == 0 assert analyzer.score("aaaaaaa") == 0.25 + 1./9 + 1./36 # unicode works just fine assert analyzer.score(u"😁😒·$aaaa") == 4./64 + 1./9 + 1./36
def choose_best_test(): analyzer = Analyzer() analyzer.feed("aaabbc") strings = ["babcaa", "cd", "bbbbbddd", "aaaaaaaaaaaaddd"] answers = analyzer.choose_best(strings, 4) assert answers[0] == strings[0] assert answers[1] == strings[3] assert answers[2] == strings[2] assert answers[3] == strings[1] answer = analyzer.choose_best(strings) assert len(answer) == 1 assert answers[0] == strings[0]
def load_test(): analyzer = Analyzer("b") assert analyzer.score("bbbb") == 0 analyzer.load(relative_path("data/sample-export-simple.txt")) assert analyzer.score("ab") == 0
def from_file_test(): analyzer = Analyzer.from_file(SAMPLE_EXPORT_FILENAME) analyzer.store(TEST_EXPORT_FILENAME) assert files_equal(TEST_EXPORT_FILENAME, SAMPLE_EXPORT_FILENAME)