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

Activity: 7.12.13 ActiveCode (ch8Ex7q) #467

Open
lryderWHS opened this issue Jan 31, 2024 · 27 comments
Open

Activity: 7.12.13 ActiveCode (ch8Ex7q) #467

lryderWHS opened this issue Jan 31, 2024 · 27 comments
Assignees

Comments

@lryderWHS
Copy link

Please check the current issues Many bug reports are duplicates, this just creates more work for us. Searching the issues first may give you your answer or a workaround! If not adding new information to an existing report is much more helpful than a new report.

What Course are you in
CSAwesome

What Page were you on
7.12. Code Practice with ArrayLists
Activity: 7.12.13 ActiveCode (ch8Ex7q)

What is your username
[email protected]

Describe the bug
The activity requires implementation of this method
public static void removeLongStrings(ArrayList list)

The error reported by the test is:
./RunestoneTests.java:16: error: method removeLongStrings in class Test1 cannot be applied to given types;
Test1.removeLongStrings(values, maxLength);
^
required: ArrayList
found: ArrayList,int
reason: actual and formal argument lists differ in length

Which seems to imply that the tester is calling the method with 2 arguments instead 1.

@bhoffman0
Copy link
Contributor

I am not able to reproduce this error. I think there may be an error in your own code. Please try this code.
public static void removeLongStrings(ArrayList list)
{
int count = 0;
while (count < list.size())
{
if (list.get(count).length() > 4)
{
list.remove(count);
}
count++;
}
}
This passes all the unit tests for me.

@lryderWHS
Copy link
Author

lryderWHS commented Feb 1, 2024 via email

@bhoffman0
Copy link
Contributor

Could you send the code that you are using and a screenshot of the compile erorrs? If you go back to the first run and run it with no code added, do you still get compile errors? I get no compile errors although the tests fail.
image

@lryderWHS
Copy link
Author

Capture2

@lryderWHS
Copy link
Author

Capture1

@lryderWHS
Copy link
Author

My thought is the compile error is coming from a unit test in a file called RunestoneTests that is calling the method on line 16 with 2 arguments, instead of one.

@gigamonkey
Copy link
Contributor

You can see the tests if you view source on the page. When I do that on https://runestone.academy/ns/books/published/csawesome/Unit7-ArrayList/listPractice.html?mode=browsing

I see this test code starting at line 1484:

import static org.junit.Assert.*;

import org.junit.*;

import java.io.*;
import java.util.ArrayList;

public class RunestoneTests extends CodeTestHelper
{
    @Test
    public void testMain() throws IOException
    {
        String output = getMethodOutput("main");
        String expect =
                "Expected Result:\t [fish, cat, foo]\n" + "Your Result:\t\t [fish, cat, foo]\n";
        boolean passed = getResults(expect, output, "Expected output from main");
        assertTrue(passed);
    }

    @Test
    public void testRemoveLongStrings()
    {
        ArrayList<String> mylist1 = new ArrayList<String>();
        mylist1.add("longword");
        mylist1.add("dog");
        mylist1.add("longword");
        mylist1.add("wee");

        ArrayList<String> mylist2 = new ArrayList<>();
        mylist2.add("dog");
        mylist2.add("wee");

        Test1.removeLongStrings(mylist1);

        boolean result = mylist2.equals(mylist1);

        boolean passed = getResults("true", "" + result, "removeLongStrings method test");
        assertTrue(passed);
    }
}

What do you see?

@gigamonkey
Copy link
Contributor

Also, what's the URL of your CSAwesome. It feels like you somehow have a different version than the latest?

@lryderWHS
Copy link
Author

This is the URL where I am experiencing the issue

https://runestone.academy/ns/books/published/csawesome/Unit7-ArrayList/listPractice.html

@bhoffman0
Copy link
Contributor

bhoffman0 commented Feb 1, 2024

Thanks, but this is a mystery! I am not seeing that behavior. The tests do not have that error-producing code, see line 724 in https://github.com/bhoffman0/CSAwesome/blob/master/_sources/Unit7-ArrayList/listPractice.rst?plain=1. I'm thinking that this is an error in a particular server which is perhaps compiling the wrong Java code. @bnmnetp is it possible to clear the cache for Java files like you do periodically on server2?
Could you please do CTRL-Shift-j and scroll up to the top of the console messages to see which server you are on?
Could you also do right click and select View Page Source as Peter suggested and look at line 1502 to see if you have Test1.removeLongStrings(mylist1); or something else there?

@lryderWHS
Copy link
Author

Capture3

@lryderWHS
Copy link
Author

When I view source code I see the correct code on line 1502
Capture4

@gigamonkey
Copy link
Contributor

gigamonkey commented Feb 1, 2024

[Edit: oh, whoops. Beryl already asked you about this. Sorry.]

Okay, next debugging step: can you open the developer tools and scroll to the top of the console where the first line should be something like:

This page served by server5

What does it say for you? It's possible that some server has a cached version of the compiled tests that's wildly out of date or something.

@lryderWHS
Copy link
Author

This page served by server2

@bnmnetp
Copy link
Member

bnmnetp commented Feb 1, 2024

@bhoffman0 I have a cron job that cleans the cache on all of the jobe servers every day, removing files more than 4 days old.

The server you are assigned is based on the IP address of your computer, so @lryderWHS would get the same server and JOBE server regardless of the course.

Now, on server 2 if I check the cache of files I do see various definitions of the removeLongStrings function with and without the second parameter sometimes called maxLength, toMaxLength, m, or x ...

These files are dated january 27 or newer.

No files like that are found on server3...

@bnmnetp
Copy link
Member

bnmnetp commented Feb 1, 2024

@bhoffman0 where could the different versions of that code be coming from? The test code is not editable by the user, unless these are variations that have been created by instructors in the web interface?

@bhoffman0
Copy link
Contributor

bhoffman0 commented Feb 1, 2024

I'm on server1 and Peter is on server5 and we created some removeLongStrings functions with 2 args to try to get the same error without success, but not on server2 and just in the student code area, not in the unit test code. I checked the question bank in assignments for 7.12 and there were no copies of any exercises in that lesson and nothing with that name or function in the exercises lesson.

@bhoffman0
Copy link
Contributor

@bnmnetp maybe delete the files with removeLongStrings on server2 and see if the problem goes away?

@bnmnetp
Copy link
Member

bnmnetp commented Feb 1, 2024

I thought of that, but I was hoping we could get to the bottom of why this happened before I make the problem vanish.

@bhoffman0
Copy link
Contributor

yeah all I could think of was the weird cache problem.

@bnmnetp
Copy link
Member

bnmnetp commented Feb 1, 2024

There are 3 questions in the database that call Test1.removeLongStrings. None of them have the second parameter.

Two of the cached files have the second parameter:
stoneca280cb55e51c1918966cbd243dfd8a2

import java.util.ArrayList;

public class RunestoneTests {
    public static void main(String[] args) {
        // instantiate ArrayList and fill with Strings
        ArrayList<String> values = new ArrayList<String>();
        String[] words = {"bathtub", "fish", "computer", "cat", "foo"};
        for (int i = 0; i < words.length; i++) {
            values.add(words[i]);
        }

        // Specify the maximum length of strings to keep (e.g., 6 in this case)
        int maxLength = 6;

        // Call removeLongStrings with both arguments
        Test1.removeLongStrings(values, maxLength);

        System.out.println("Expected Result:\t [fish, cat, foo]");
        System.out.println("Your Result:\t\t " + values);
    }
}

and stonecf111f2de0694dbce8df108ecddb5f32

import java.util.ArrayList;

public class Test1
{
    public static void removeLongStrings(ArrayList<String> list)
    {
        // code here
    }

    public static void main(String[] args)
    {
        // instantiate ArrayList and fill with Integers
        ArrayList<String> values = new ArrayList<String>();
        String[] words = {"bathtub", "fish", "computer", "cat", "foo"};
        for (int i = 0; i < words.length; i++)
        {
            values.add(words[i]);
        }
        Test1.removeLongStrings(values, words.length);
        System.out.println("Expected Result:\t [fish, cat, foo]");
        System.out.println("Your Result:\t\t " + values);
    }
}

And timestamps:

root@e5537f499757:/home/jobe/files/ru/ne# ls -l stonecf111f2de0694dbce8df108ecddb5f32
-rw-r--r-- 1 www-data www-data 735 Jan 27 14:07 stonecf111f2de0694dbce8df108ecddb5f32
root@e5537f499757:/home/jobe/files/ru/ne# ls -l stoneca280cb55e51c1918966cbd243dfd8a2
-rw-r--r-- 1 www-data www-data 677 Jan 30 14:27 stoneca280cb55e51c1918966cbd243dfd8a2
root@e5537f499757:/home/jobe/files/ru/ne# more stoneca280cb55e51c1918966cbd243dfd8a2        

@bnmnetp
Copy link
Member

bnmnetp commented Feb 1, 2024

With that, I have now removed those two files from the cache on server2. @lryderWHS hopefully that solves your problem.

@bnmnetp
Copy link
Member

bnmnetp commented Feb 1, 2024

Was the removal of the second parameter a change that @bhoffman0 or @gigamonkey made recently? A change you recall from the distant past?

@bhoffman0
Copy link
Contributor

No, I looked at git blame and that problem hasn't been touched in 4 years, other than the reformatter 7 months ago which only changed spacing. (line 724 in https://github.com/bhoffman0/CSAwesome/blame/master/_sources/Unit7-ArrayList/listPractice.rst).
Maybe it got confused because someone renamed their class RunestoneTests in that first cached file.

@lryderWHS
Copy link
Author

Looks fixed on my end :) Yay!! I appreciate all the time an energy!!!

@bhoffman0
Copy link
Contributor

@bnmnetp We've had reports of two more incidents of the code working on one server but not another: in email in 7.4.6.3.1 ActiveCode CookieOrder and https://discord.com/channels/1013815439161315348/1013892589776281620/1204144692174790686 on server1. All in Unit 7 but that might just be because that's where most classes are.
Maybe we should expand the cache clearing to files older than 2 days instead of 4?

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

No branches or pull requests

4 participants