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

Reworked HashDictionary #494

Merged

Conversation

marcusnaslund
Copy link
Contributor

Adds missing tests for HashDictionary and VectorList.
Some cleanup of HashDictionary. More can be done (it uses ArrayList and HashBag from the sdk for example) but we can look at that if/when we will use this class.
Right now it doesn't seem to be used (see #460 )

for ((index, item) in iterator)
expect(item, is equal to(list[index]))
expect(iterator hasNext?(), is equal to(false))
secondIterator := list iterator()
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to free secondIterator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thomasfanell I've seen many tests where nothing at all is freed. I thought I was just being pedantic sometimes. But you're right, will fix.

@@ -3,15 +3,30 @@ import structs/[HashBag, HashMap, ArrayList]
HashDictionary: class {
_myHashBag: HashBag
_capacity: Int
size ::= this _myHashBag size()
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be a good idea to call this count instead, as in our other collections? (just this class, don't change anything in HashBag)

@marcusnaslund
Copy link
Contributor Author

Fixed according to comments.

@@ -104,7 +104,7 @@ HashDictionaryTest: class extends Fixture {
dictionary add("First", 1337)
expect(dictionary getAsType("First", Int) == 1337)
expect(dictionary getAsType("First", String) == null)
expect(dictionary getAsType("Second", Int) == null)
//expect(dictionary getAsType("Second", Int) == null) //FIXME Can we do this without obnoxious Pointer-To-Int warnings?
Copy link
Contributor

Choose a reason for hiding this comment

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

getAsType: func <T>(key: String, T: Class) -> T {, which means that dictionary getAsType("Second", Int) will return an Int. If you compare an Int to null, you will get the warning. If the test would follow the warning The Class parameter for Covers must be Cell<Cover> by calling dictionary getAsType("Second", Cell<Int>) the warning should go away, but then you also need to use Cell when adding things to the dictionary, or things will go badly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, this should be solved as I did with Future. Will fix.

@marcusnaslund marcusnaslund changed the title Completion of Collections tests Completion of Collections tests + reworked HashDictionary Oct 5, 2015
@marcusnaslund
Copy link
Contributor Author

The updated HashDictionary now handles wrapping of covers into cells automatically (like Promise) - no need to do it manually and no bothersome warnings in the test.

expect(dictionary get("TestClassValue", this defaultClass) stringVal == "String", is true)
expect(dictionary get("Nonexistent", this defaultClass) stringVal == "Default", is true)
expect(dictionary get("TestClassValue", this defaultClass) intVal == 1, is true)
expect(dictionary get("Nonexistent", this defaultClass) intVal == 0, is true)
})
this add("ArrayList", func {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not an ArrayList anymore, so you should change this thing as well.

@marcusnaslund
Copy link
Contributor Author

Updated: _myHashBag renamed to _hashBag, first2 renamed to second and ArrayList test renamed to VectorList.


init: func(=val)
init: func ~withtype(=val, =type)
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you need this for, anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, the sdk uses spaces, I see.
This is to please the get functions in HashDictionary - I need to store the classtype T in order to check whether the requested type actually exists for a particular key.


init: func(=val)
init: func ~withtype(=val, =type)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should add this just to get HashDictionary (which we're not even using) working. Besides, Cell should already know what T is, it shouldn't need to be stored like this. I'm going to let this sit for a while until someone comes up with a better idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could store the classtype in HashEntry instead perhaps?

@marcusnaslund
Copy link
Contributor Author

Updated with cleanup of VectorListTest.
Possibly, the HashDictionary update should be a separate PR - since we don't seem to be clear on what to do with it (and it will require more work anyhow). Then the rest of the stuff here has a chance of getting passed faster. What do you think?

@davidhesselbom
Copy link
Contributor

Yes, split it up.

@marcusnaslund marcusnaslund changed the title Completion of Collections tests + reworked HashDictionary Reworked HashDictionary Oct 13, 2015
@davidhesselbom davidhesselbom self-assigned this Oct 27, 2015
@marcusnaslund
Copy link
Contributor Author

Couldn't find a need for getAsType - it's been removed.

@@ -1,97 +1,90 @@
import structs/[HashBag, HashMap, ArrayList]

HashDictionary: class {
_myHashBag: HashBag
_hashBag: HashBag
_capacity: Int
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't look like this is actually used for anything at all. Fix now, or fix later? Your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now.

@marcusnaslund
Copy link
Contributor Author

Updated and ready.

davidhesselbom added a commit that referenced this pull request Oct 28, 2015
@davidhesselbom davidhesselbom merged commit e78108f into magic-lang:master Oct 28, 2015
@marcusnaslund marcusnaslund deleted the missing-collections-tests-v2 branch November 2, 2015 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants