Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daniel Dewan Grammar Homework #50

Closed
wants to merge 4 commits into from

Conversation

danieldewan
Copy link

Daniel Dewan
47685941

@@ -53,7 +57,7 @@ In one sentence, explain why.

## A1.2

«replace this with your answer»
O(n) because it has to perform n/2 comparisons because it has to check if the first and the last time are equal, the second and the second to last, etc.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right answer, but in fact it has to do many more comparisons than that, because it doesn't know where the end is until it reaches it...

Comment on lines +194 to +195
g++ -std=c++11 sentence.cpp
./a.out
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You used a hash table with is great. But your testing wasn't really testing: it just output stuff about sentences. An automated test should know the expected result and make it clear when the function being tested fails to produce it.

Also, a bunch of people wrote code like this:

    vector<string> s1 = { "the", "cat", "ate", "EOI" };
    vector<string> s2 = {"the", "dog", "ran", "slowly", "EOI"};
    vector<string> s3 = {"the", "lazy", "cat", "ran", "slowly", "EOI"};
    vector<string> s4 = {"the", "smelly", "dog", "ran", "EOI"};
    vector<string> s5 = {"smelly", "dog", "ran", "EOI"};
    vector<string> s6 = {"the", "cat", "ate"};
    vector<string> s7 = {"the", "cat", "EOI"};
    vector<string> s8 = {"the", "smelly", "lazy", "cat", "ate", "EOI"};

    vector<vector<string> > sentences;

    sentences.push_back(s1);
    sentences.push_back(s2);
    sentences.push_back(s3);
    sentences.push_back(s4);
    sentences.push_back(s5);
    sentences.push_back(s6);
    sentences.push_back(s7);
    sentences.push_back(s8);

I don't get it. C++ is already verbose enough without adding to your woes. How about:

    vector<vector<string>> sentences {
        { "the", "cat", "ate", "EOI" },
        {"the", "dog", "ran", "slowly", "EOI"},
        {"the", "lazy", "cat", "ran", "slowly", "EOI"},
        {"the", "smelly", "dog", "ran", "EOI"},
        {"smelly", "dog", "ran", "EOI"},
        {"the", "cat", "ate"},
        {"the", "cat", "EOI"},
        {"the", "smelly", "lazy", "cat", "ate", "EOI"}
    };

(No deduction for that, but -2 for the tests)

-2

@pragdave
Copy link
Owner

pragdave commented Apr 7, 2020

In general never add derived files (executables, .obj, etc) to a repository.
They are typically useless to anyone else, because they are build for your
particular environment.

Other than that, very nice work. I found nothing substantive to comment on; just a small ding on the tests.

@pragdave pragdave closed this Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants