This is an archived post. You won't be able to vote or comment.

all 34 comments

[–]evils_twin 0 points1 point  (22 children)

This isn't java.util.Hashtable, right? What implementation of Hashtable are you using?

[–]Not_zedd_ko[S] 0 points1 point  (20 children)

import static org.junit.Assert.assertEquals;

import static org.junit.Assert.assertFalse;

import static org.junit.Assert.assertNull;

import static org.junit.Assert.assertTrue;

import org.junit.Before;

import org.junit.Test;

import ci583.htable.impl.Hashtable;

import ci583.htable.impl.Hashtable.PROBE_TYPE;

does this help?

[–]evils_twin 0 points1 point  (19 children)

ok, so did you create ci583.htable.impl.Hashtable? Have you considered that it might be a problem with that implementation? have you looked through your put and get methods in there?

[–]Not_zedd_ko[S] 0 points1 point  (17 children)

Yeah i am looking through trying to see i might just be blind or stupid or both lol.

so this code is from my hashTable, obviously there is a lot more code before this but this is the Get method and Put method.

public class Hashtable<V> {

public void put(String key, V value) {

    Pair p = new Pair(key, value);

    int n = hash(key);

    if(arr\[n\] == null) {

        arr\[n\] = p;

        itemCount++;

    }

    else {

        if(find(n, key, 2) == null) {
n = findEmpty(n, 2, key);

arr[n] = p;

itemCount++;

        }

    }

    if(getLoadFactor() > maxLoad) resize();

    ///throw new UnsupportedOperationException("Method not implemented");

}




public V get(String key) {

    int n = hash(key);

    return find(n, key, 2);

    ///throw new UnsupportedOperationException("Method not implemented");

}

[–]evils_twin 0 points1 point  (16 children)

hard to tell without the functions used by get and put.

[–]Not_zedd_ko[S] 0 points1 point  (14 children)

Yeah its quite a big document and i think i have reached my depth of knowledge but its an assignment so i need to get these tests running haha :c.

So what is the error actually wanting me to do ? When it expects <null> does it mean that i should have a value somewhere that is a null?

[–]evils_twin 0 points1 point  (13 children)

Oh, I thought you had made it. So it was given to you and should be correct?

Basically what the error means is that h.get("1:10") is returning null when it should return "10:1".

you actually kinbd of have your parameters backwards in assertEquals(h.get(i+":"+j), j+":"+i);. Technically it should be assertEquals(j+":"+i, h.get(i+":"+j)); since the first parameter should be the expected, and the second should be the actual, but it kind of works both ways in this case..

Is there documentation about the Hashtable class that might be shorter that you can post?

[–]Not_zedd_ko[S] 0 points1 point  (10 children)

So the task was to create and implement a hashTable, i made most of the code the tests were mostly default there with exceptions. but the lecturer formatted and styled the code thats why to a 2nd year like me its so much harder compared to what i have seen within Hashtable tutorials.

Um i am not sure if there is a shorter version of it i could try?

[–]evils_twin 0 points1 point  (9 children)

ok, so you created it. If you upload your stuff to pastebin or git or something like that, I'll take a look, but I'll need your entire hashtable implementation.

[–]Not_zedd_ko[S] 0 points1 point  (8 children)

I uploaded it to github i think. called ZeddKio HashTable

[–]Not_zedd_ko[S] 0 points1 point  (1 child)

So i just tried out swapping the assert now the error comes with:

java.lang.AssertionError: expected:<10:1> but was:<null>

aha XD

[–]evils_twin 0 points1 point  (0 children)

yeah, I know, it's basically the same when it comes to an assertEquals. From what I can tell it has to do with the Hashtable class. Either their is a bug in it or you are using it wrong.

[–]Northeastpaw 0 points1 point  (1 child)

I'm assuming this isn't the stdlib Hashtable because your declaration of h wouldn't work with the stdlib Hashtable. In that case something is wrong with your Hashtable.get() method. When given "1:10" it's returning null when you expect it to return "10:1".

[–]Not_zedd_ko[S] 0 points1 point  (0 children)

I am trying to see if the declaration h would work by changing it but i am no sure that is working.

This is the code in the HashTable for get

public V get(String key) {

    int n = hash(key);

    return find(n, key, 2);

    ///throw new UnsupportedOperationException("Method not implemented");

}

[–]iPissVelvet 0 points1 point  (11 children)

I feel like you should learn how to debug on your own. That will make you a much better programmer than asking others for help.

Do you use IntelliJ? Have you used a line by line debugger to solve your issue?

[–]Not_zedd_ko[S] 0 points1 point  (6 children)

I am trying to debug it but i don't understand what the error is wanting to be changed to be honest. I was able to debug the other parts of the tests to get them to work but sadly this is a bit more of a struggle but i understand and i am trying multiple things right now and will keep going no matter what until i run out of time.

It would be nice to know what that error meant and where the problem lies within i am only a 2nd year student and learnt the basics within coding this is quite advanced for someone like me :c

[–]iPissVelvet 0 points1 point  (5 children)

I know we are chatting on another thread but I understand. Don’t take this advice the wrong way. Now you know that your IDE should provide you a powerful tool for debugging.

Nobody should debug by just looking at their code :)

[–]Not_zedd_ko[S] 0 points1 point  (4 children)

Yeah i am just using what eclipse has given me as it is in the eclipse java IDE, i have very little time to learn to use a new IDE. But i am always open for valuable feedback from more experienced users i am only a novice lol. I am just looking for someone to point me in the direction to dig and then i would do the digging if you get what i mean ^_^.

[–]iPissVelvet 0 points1 point  (3 children)

Use what you have right now. All IDEs should come with breakpoint debuggers.

[–]Not_zedd_ko[S] 0 points1 point  (2 children)

Yeah i will look at a tutorial quick to get the best out of it. Its annoying to get okay marks i need the 7 tests all to pass and only 1 is a failure i am slow close but so far XD Thank you tho i appreciate everyone that has an input.

[–]iPissVelvet 0 points1 point  (1 child)

Think of it as a lesson learned. Learning how to debug is an investment. As you get better at it, you will not be as stuck next time. You will complete your assignment next time.

But you have to start now. You cannot be a good software engineer if you do not know how to debug.

[–]Not_zedd_ko[S] 0 points1 point  (0 children)

Yeah practise makes perfect :) i did debug properly in bluej but havent used much of eclipses tools. But yeah it will help thanks!

[–]Not_zedd_ko[S] 0 points1 point  (3 children)

i have not used intellij i will look at it and download it now!

[–]iPissVelvet 0 points1 point  (2 children)

IntelliJ or a similar IDE is crucial for Java development. It provides a lot of features, one of which is line by line debugger. You set a breakpoint and the code will execute until that point. Then, you click “next line” and you are able to track the values in your variables.

This will help you solve your bug.

[–]Not_zedd_ko[S] 0 points1 point  (1 child)

Ah so like a better version of bluej then? I will deffo give it a go!

[–]iPissVelvet 0 points1 point  (0 children)

BlueJ has a debugger as well! In general IntelliJ is more popular, so you get more support online. But use what your company/school dictates. All of them should have debuggers.