Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(61)

Issue 52057: option to run the tests in a random order

Can't Edit
Can't Publish+Mail
Start Review
Created:
16 years, 9 months ago by Josh Kelley
Modified:
11 years, 1 month ago
Reviewers:
Zhanyong Wan
CC:
googletestframework_googlegroups.com
Base URL:
http://googletest.googlecode.com/svn/trunk/
Visibility:
Public.

Patch Set 1 #

Total comments: 44

Patch Set 2 : test shuffling - flag parsing and management only #

Total comments: 6

Patch Set 3 : option to run the tests in a random order #

Patch Set 4 : option to run the tests in a random order #

Total comments: 3

Patch Set 5 : final patch implementing running tests in a random order #

Total comments: 42
Unified diffs Side-by-side diffs Delta from patch set Stats (+269 lines, -2 lines) Patch
M include/gtest/gtest.h View 1 2 3 1 chunk +5 lines, -0 lines 0 comments Download
M src/gtest.cc View 1 2 3 4 5 chunks +27 lines, -2 lines 9 comments Download
M src/gtest-internal-inl.h View 1 2 3 4 chunks +53 lines, -0 lines 16 comments Download
M test/gtest_unittest.cc View 1 2 3 4 1 chunk +184 lines, -0 lines 17 comments Download

Messages

Total messages: 8
Zhanyong Wan
Hi Josh, I apologize for the massive delay. In general I like what I'm seeing. ...
16 years, 7 months ago (2009-06-16 06:35:11 UTC) #1
Zhanyong Wan
One thing I learned from this is that big patches can take a long time ...
16 years, 7 months ago (2009-06-18 21:10:15 UTC) #2
Josh Kelley
I uploaded a reduced patch set, as you suggested, that only implements parsing, managing, and ...
16 years, 7 months ago (2009-06-25 02:07:02 UTC) #3
Zhanyong Wan
http://codereview.appspot.com/52057/diff/1/3 File include/gtest/internal/gtest-internal.h (right): http://codereview.appspot.com/52057/diff/1/3#newcode761 Line 761: explicit Random(UInt32 state = 1) : state_(state) {} ...
16 years, 6 months ago (2009-06-29 21:20:16 UTC) #4
Josh Kelley
A general question: I assume that assertions are a good idea, even if existing code ...
16 years, 6 months ago (2009-07-10 02:16:44 UTC) #5
Zhanyong Wan
Thanks for keeping working on this, Josh! http://codereview.appspot.com/52057/diff/9001/9003 File test/gtest_list_tests_unittest.py (right): http://codereview.appspot.com/52057/diff/9001/9003#newcode57 Line 57: BarDeathTest. ...
16 years, 4 months ago (2009-09-22 05:46:24 UTC) #6
Josh Kelley
http://codereview.appspot.com/52057/diff/9001/9003 File test/gtest_list_tests_unittest.py (right): http://codereview.appspot.com/52057/diff/9001/9003#newcode57 Line 57: BarDeathTest. On 2009/09/22 05:46:24, Zhanyong Wan wrote: > ...
16 years, 4 months ago (2009-09-23 03:35:19 UTC) #7
Zhanyong Wan
16 years, 4 months ago (2009-09-23 05:28:08 UTC) #8
http://codereview.appspot.com/52057/diff/11001/12003
File src/gtest-internal-inl.h (right):

http://codereview.appspot.com/52057/diff/11001/12003#newcode405
Line 405: GTEST_CHECK_(0 <= from && from <= size_)
On 2009/09/23 03:35:19, Josh Kelley wrote:
> On 2009/09/22 05:46:24, Zhanyong Wan wrote:
> > from should be < size.
> 
> Since to == size is permitted (to shuffle the entire list), and since from ==
to
> is permitted (shuffle an empty range), then from == size should be permitted. 
> If from cannot equal size, then we'd have to add special cases to handle,
e.g.,
> shuffling a test suite containing only death test cases.

Makes sense!

http://codereview.appspot.com/52057/diff/11001/12003#newcode420
Line 420: const int k = random->Generate(n - from) + from;  // from <= k < n
On 2009/09/23 03:35:19, Josh Kelley wrote:
> On 2009/09/22 05:46:24, Zhanyong Wan wrote:
> > It's slightly more intuitive like this:
> > 
> > for (int range_width = to - from; range_width >= 2; range_width--) {
> >   const int last_in_range = from + range_width - 1;
> >   const int selected = from + random->Generate(range_width);
> >   Swap(selected, last_in_range);
> > }
> > 
> > - The termination condition is more intuitive: the range must contain >= 2
> > elements to be worth shuffling.
> > - Give the two elements being swapped meaningful names.
> > 
> 
> I took the code with almost no modification from Wikipedia, which apparently
> took the algorithm (including the variable names n and k) from Durstenfield's
> and Knuth's work.  I see how your approach is clearer for those new to the
code,
> but I would guess that people familiar with the algorithm or reading the
> complete Wikipedia article would find Wikipedia's approach clearer.  Thoughts?

The code should be as self-contained and self-explaining as possible.  It's a
distraction to ask the reader to open a web page and read it.

This algorithm is simple enough that one doesn't need to read the wikipedia
entry to understand how it works.  We should optimize for people who don't read
the article.  Also, the code I wrote is implementing the same algorithm - just a
different encoding.  I don't think people who already know about the wiki
article or Knuth's work will be confused, unless they memorize it word by word
without understanding the essence of it - in that case I don't feel sorry for
them. :-)

http://codereview.appspot.com/52057/diff/11001/12004
File src/gtest.cc (right):

http://codereview.appspot.com/52057/diff/11001/12004#newcode3703
Line 3703: random_(1),
On 2009/09/23 03:35:19, Josh Kelley wrote:
> On 2009/09/22 05:46:24, Zhanyong Wan wrote:
> > Why 1?
> 
> A default c'tor for Random didn't really seem appropriate, so I needed some
seed
> to use until we got a random seed from flags or from the clock, and 0 is a
> special case and not a valid seed, so I picked 1.  Although I guess seemingly
> magic numbers are bad too.  What would be a better approach?

The fact that 0 is not a seed usable by the user makes it a good choice here. 
This tells the reader "we are just initializing random_ with an invalid seed
here, and we'll reseed it later, so don't read too much into the seed value."

I'd suggest to initialize it with 0 and add a comment that we'll reseed it
before first use.

http://codereview.appspot.com/52057/diff/11001/12001
File test/gtest_unittest.cc (right):

http://codereview.appspot.com/52057/diff/11001/12001#newcode790
Line 790: static const int kVectorSize = 20;
On 2009/09/23 03:35:19, Josh Kelley wrote:
> On 2009/09/22 05:46:24, Zhanyong Wan wrote:
> > Style: data members should be defined at the end of the class.
> 
> The style guide says constants go towards the beginning?

You're absolutely right.  Ashamed that I didn't do my homework. :)

http://codereview.appspot.com/52057/diff/11001/12001#newcode890
Line 890: EXPECT_EQ(kVectorSize - 1, vector_.GetElement(kVectorSize - 1));
On 2009/09/23 03:35:19, Josh Kelley wrote:
> On 2009/09/22 05:46:24, Zhanyong Wan wrote:
> > Why this?
> 
> It's sort of a precondition, or a test of the test code, to make sure that the
> list is set up as this test expects and that the assertions below won't
> accidentally pass.

In general, we don't test the test code, as it obscures the intention of the
test.  (It confused me in this case, for example.)  Instead, the test code
itself should be obviously correct.  If that's not the case, we probably have a
bigger problem.

Pretty much all tests in VectorShuffleTest depends on vector_ being {0,1,2,...}.
 We don't assert it else where.  I don't think we need to make a special case
here.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b