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

WIP: Align stack size with long size and add generators #898

Merged
merged 8 commits into from May 28, 2019

Conversation

vilu
Copy link
Contributor

@vilu vilu commented May 25, 2019

Just opening this up for some feedback, will continue to clean up and push to this.

@vilu vilu mentioned this pull request May 25, 2019
@vilu
Copy link
Contributor Author

vilu commented May 25, 2019

I've added generators (I'll clean up later) however, seems like the large push/pop test broke. Will have to check that implementation too.

@vilu
Copy link
Contributor Author

vilu commented May 25, 2019 via email

@vilu vilu force-pushed the 860-stack-bool-fix-and-generators branch from a9b7daa to 0424cd7 Compare May 25, 2019 14:42
* Add generators to tests

* Fix push/pop methods

* Fix getOrElse method to work with multiple entries

Co-Authored-By: Regis Kuckaertz <regis.kuckaertz@guardian.co.uk>
@vilu vilu force-pushed the 860-stack-bool-fix-and-generators branch from 0424cd7 to b5a411f Compare May 25, 2019 14:44
@vilu
Copy link
Contributor Author

vilu commented May 25, 2019 via email

@tkroman
Copy link

tkroman commented May 25, 2019

yes, i mean there is no need for assert on this because i is immutable, there was an assert before on j because it changes in the loop, so maybe you want to change to assert on the value of ie (the variable one)?

@vilu
Copy link
Contributor Author

vilu commented May 26, 2019

I ended up removing the assertion. Thanks for pointing it out.

Copy link
Contributor

@LGLO LGLO left a comment

Choose a reason for hiding this comment

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

Thank you! Generally looks very good. I think one null check is missing in while in getOrElse.
For "laws" I like ScalaCheck, but we still can have simple checks for some scenarios, like getting element with too high index.

@vilu
Copy link
Contributor Author

vilu commented May 26, 2019

@LGLO, @regiskuckaertz thanks for your feedback. I've tried to address your comments.

@vilu
Copy link
Contributor Author

vilu commented May 26, 2019

For "laws" I like ScalaCheck, but we still can have simple checks for some scenarios, like getting element with too high index.

@LGLO Can you think of any other case besides too high index (I've added one check there)?


((1L << index) & entry.bits) != 0L
}

final def popDrop[A](a: A): A = { popOrElse(false); a }

final def toList: List[Boolean] =
(0 until _size.toInt).map(getOrElse(_, false)).toList.reverse
Copy link
Contributor

Choose a reason for hiding this comment

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

IDK if there are any laws that bind stack and list, but my intuition is that toList should yield same result (besides mutation) like pop-ing all elements. However non-mutating toList is just inefficient and I consider this as "debug" method only.

Copy link
Contributor Author

@vilu vilu May 27, 2019

Choose a reason for hiding this comment

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

Yes, I was thinking about that too. I had a quick look around and I was seeing different behaviours which made me think that it should just continue the way it behaved before.

import java.util.Stack;
import java.util.ArrayList;

public class Main {
    public static void main(String args[]) {
        Stack<Boolean> stack = new Stack<Boolean>();
        stack.push(true);
        stack.push(true);
        stack.push(false);
        stack.push(true);
        stack.push(false);
        ArrayList<Boolean> list = new ArrayList(stack);
        for (int i = 0; i < list.size(); i++) {
          System.out.println(list.get(i));
        }
    }
}

// true
// true
// false
// true
// false
---------------------------------
scala> res27
res29: s.type = Stack(false, true, false, true, true)

scala> res27.toList
res30: List[Boolean] = List(false, true, false, true, true)
---------------------------------
val s = StackBool()

s.push(true)
s.push(true)
s.push(false)
s.push(true)
s.push(false)


println(s.toList)
//List(false, true, false, true, true)

@LGLO
Copy link
Contributor

LGLO commented May 26, 2019

@vilu From my side it looks OK! I don't merge right now because I'd like to take another look but I don't have time today. I'll take a look tomorrow.

@LGLO LGLO merged commit 550e256 into zio:master May 28, 2019
@jdegoes
Copy link
Member

jdegoes commented May 29, 2019

@vilu Thank you!

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.

None yet

5 participants