def test_extract_sentiment():
    print("Testing extract_sentiment() functionality...")
    chatbot = Chatbot(False)

    # add more test cases here!!!
    test_cases = [
        ('I like "Titanic (1997)".', 1),
        ('I saw "Titanic (1997)".', 0),
        ('I didn\'t enjoy "Titanic (1997)".', -1),
        ('I didn\'t really like "Titanic (1997)".', -1),
        ('I never liked "Titanic (1997)".', -1),
        ('I really enjoyed "Titanic (1997)".', 1),
        ('"Titanic (1997)" started out terrible, but the ending was totally great and I loved it!',
         1),
        ('I loved "10 Things I Hate About You"', 1),
    ]

    tests_passed = True
    for input_text, expected_output in test_cases:
        if not assertEquals(
                chatbot.extract_sentiment(
                    chatbot.preprocess(input_text)), expected_output,
                "Incorrect output for extract_sentiment(chatbot.preprocess('{}'))."
                .format(input_text)):
            tests_passed = False
    if tests_passed:
        print('extract_sentiment() sanity check passed!')
    print()
Example #2
0
def test_extract_sentiment():
    print("Testing extract_sentiment() functionality...")
    chatbot = Chatbot(False)
    if assertEquals(
            chatbot.extract_sentiment("I like \"Titanic (1997)\"."), 1,
            "Incorrect output for extract_sentiment(\'I like \"Titanic (1997)\".\')"
    ) and assertEquals(
            chatbot.extract_sentiment("I saw \"Titanic (1997)\"."), 0,
            "Incorrect output for extract_sentiment(\'I saw  \"Titanic (1997)\".\')"
    ) and assertEquals(
            chatbot.extract_sentiment("I didn't enjoy \"Titanic (1997)\"."),
            -1,
            "Incorrect output for extract_sentiment(\'I didn't enjoy  \"Titanic (1997)\"\'.)"
    ) and assertEquals(
            chatbot.extract_sentiment("I saw \"Titanic (1997)\"."), 0,
            "Incorrect output for extract_sentiment(\'I saw  \"Titanic (1997)\"\'.)"
    ) and assertEquals(
            chatbot.extract_sentiment(
                " \"Titanic (1997)\" started out terrible, but the ending was totally great and I loved it!"
            ), 1,
            "Incorrect output for extract_sentiment(\" \"Titanic (1997)\" started out terrible, but the ending was totally great and I loved it!\'.\")"
    ) and assertEquals(
            chatbot.extract_sentiment(
                "I loved \"10 Things I Hate About You\""), 1,
            "Incorrect output for extract_sentiment(\'I loved  \"10 Things I Hate About You\"\')"
    ) and assertEquals(
            chatbot.extract_sentiment(
                "I saw \"The Notebook\" and it was great!"), 1,
            "Incorrect output for extract_sentiment(\'I saw \"The Notebook\" and it was great!\')"
    ):
        print('extract_sentiment() sanity check passed!')
    print()
Example #3
0
def test_extract_sentiment():
    print("Testing extract_sentiment() functionality...")
    chatbot = Chatbot(False)
    if assertEquals(
        chatbot.extract_sentiment("I like \"Titanic (1997)\"."),
        1,
        "Incorrect output for extract_sentiment(\'I like \"Titanic (1997)\".\')"
    ) and assertEquals(
        chatbot.extract_sentiment("I saw \"Titanic (1997)\"."),
        0,
        "Incorrect output for extract_sentiment(\'I saw  \"Titanic (1997)\".\')"
    ) and assertEquals(
        chatbot.extract_sentiment("I didn't enjoy \"Titanic (1997)\"."),
        -1,
        "Incorrect output for extract_sentiment(\'I didn't enjoy  \"Titanic (1997)\"\'.)"
    ):
        print('extract_sentiment() sanity check passed!')
    print()
Example #4
0
def test_extract_sentiment():
    print("Testing extract_sentiment() functionality...")
    chatbot = Chatbot(False)
    if assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I like \"Titanic (1997)\".")), 1,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I like \"Titanic (1997)\".\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I loved \"Zootopia\"")), 2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I loved \"Zootopia\"\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("\"Zootopia\" was terrible.")), -2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'\"Zootopia\" was terrible.\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I really reeally liked \"Zootopia\"!!!")),
            2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I really reeally liked \"Zootopia\"!!!\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I saw \"Titanic (1997)\".")), 0,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I saw  \"Titanic (1997)\".\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I didn't enjoy \"Titanic (1997)\".")), -1,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I didn't enjoy \"Titanic (1997)\"\'.))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I loved \"10 Things I Hate About You\".")),
            2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I loved \"10 Things I Hate About You\"\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I liked \"She's the Man\".")), 1,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I liked \"She's the Man\"\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I liked \"Sydney White\".")), 1,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I liked \"Sydney White\"\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I liked \"Easy A\".")), 1,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I liked \"Easy A\"\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("\"Easy A\" is a movie I hate.")), -2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'\"Easy A\" is a movie I hate.\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I hated \"Easy A\".")), -2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I hated \"Easy A\".\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("This movie, \"Easy A\", is really bad.")),
            -2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'This movie, \"Easy A\", is really bad.\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess(
                    "\"Titanic (1997)\" started out terrible, but the ending was totally great and I loved it!"
                )), 2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'\"Titanic (1997)\" started out terrible, but the ending was totally great and I loved it!\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess(
                    "I didn't really like \"Titanic (1997)\".")), -1,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I didn't really like \"Titanic (1997)\".\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I never liked \"Titanic (1997)\".")), -1,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I never liked \"Titanic (1997)\".\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess("I really enjoyed \"Titanic (1997)\".")), 1,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I really enjoyed \"Titanic (1997)\".\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess(
                    "I don't think I really enjoyed \"Titanic (1997)\".")), -1,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I don't think I really enjoyed \"Titanic (1997)\".\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess(
                    "I don't think I enjoyed \"Titanic (1997)\" because the plot was really bad and the acting was terrible."
                )), -2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I don't think I enjoyed \"Titanic (1997)\" because the plot was really bad and the acting was terrible.\'))"
    ) and assertEquals(
            chatbot.extract_sentiment(
                chatbot.preprocess(
                    "I didn't like \"Titanic (1997)\" at the beginning, but at the end I thought it was great and really amazing."
                )), 2,
            "Incorrect output for extract_sentiment(chatbot.preprocess(\'I didn't like \"Titanic (1997)\" at the beginning, but at the end I thought it was great and really amazing.\'))"
    ):
        print('extract_sentiment() sanity check passed!')
    print()