コード例 #1
0
ファイル: test_stage2.py プロジェクト: andreebrazeau/markov
def test_sentence_generation():
    mapping = markov.process_file("sample3.txt")
    print mapping
    random.seed(1)
    received = markov.build_sentence(mapping)
    expected = "how are you doing?"
    print "Expected output:", expected
    print "Your output:", received
    assert expected == received, """\
コード例 #2
0
def test_sentence_generation():
    mapping = markov.process_file("sample3.txt")
    print mapping
    random.seed(1)
    received = markov.build_sentence(mapping)
    expected = "how are you doing?"
    print "Expected output:", expected
    print "Your output:", received
    assert expected == received, """\
コード例 #3
0
ファイル: test_stage1.py プロジェクト: andreebrazeau/markov
def test_phrase_generation():
    assert fn_exists("build_sentence"), """\
Now that we've produced a super simple markov mapping, we need to check to see if we can use it to build a phrase. We'll start by creating a function with the following signature:

    build_sentence(dict) => str

The dictionary that it accepts is the markov mapping we produced in our process_file function.

Notice how we are explicit about inputs and return values from our function, and how the output of the other function is used as the input to this one. So far, we've been using global variables to store our intermediate values, which is considered a bad practice."""

    your_sentence = markov.build_sentence({("this", "old"): ["man."]})
    expected = "this old man."
    print "Expected sentence:", expected
    print "Your sentence:", your_sentence
    assert your_sentence == expected, """\
コード例 #4
0
def test_phrase_generation():
    assert fn_exists("build_sentence"), """\
Now that we've produced a super simple markov mapping, we need to
check to see if we can use it to build a phrase. We'll start by
creating a function with the following signature:

    build_sentence(dict) => str

The dictionary that it accepts is the markov mapping we produced in
our process_file function.

Notice how we are explicit about inputs and return values from our
function, and how the output of the other function is used as the
input to this one. So far, we've been using global variables to store
our intermediate values, which is considered a bad practice."""

    your_sentence = markov.build_sentence({("this", "old"): ["man."]})
    expected = "this old man."
    print "Expected sentence:", expected
    print "Your sentence:", your_sentence
    assert your_sentence == expected, """\
コード例 #5
0
def test_cap():
    mapping = markov.process_file("emma.txt")
    for i in range(5):
        s = markov.build_sentence(mapping)
        print "Sentence generated:", s
        assert s[0] == s[0].capitalize(), """\
コード例 #6
0
ファイル: test_stage3.py プロジェクト: andreebrazeau/markov
def test_cap():
    mapping = markov.process_file("emma.txt")
    for i in range(5):
        s = markov.build_sentence(mapping)
        print "Sentence generated:", s
        assert s[0] == s[0].capitalize(), """Everything's looking pretty good now, you can generate tweets and sentences and paragraphs, the last detail is that sentences are generated with a lowercase letter to start. Make sure that the first word of each sentence is capitalized properly."""
コード例 #7
0
def test_cap():
    mapping = markov.process_file("emma.txt")
    for i in range(5):
        s = markov.build_sentence(mapping)
        print "Sentence generated:", s
        assert s[0] == s[0].capitalize(), """\