Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src



On Wed, 28 Mar 2012, Jukka Ruohonen wrote:
+ATF_TC_BODY(random_zero, tc)
+{
+       const size_t n = 1000000;
+       size_t i, j;
+       long x;
+
+       srandom(0);
+
+       for (i = j = 0; i < n; i++) {
+
+               if ((x = random()) == 0)
+                       j++;
+       }
+
+       ATF_REQUIRE(j != n);
+}

n=4 would probably be enough iterations, and I'd suggest checking whether all values are the same as each other, rather than checking whether all values are zero.

--apb (Alan Barrett)
From: Alan Barrett <apb%cequrux.com@localhost>
To: source-changes-d%NetBSD.org@localhost
Cc: Bcc: Subject: Re: CVS commit: src Reply-To: In-Reply-To: <20120328103358.4BB33175D0%cvs.netbsd.org@localhost>

On Wed, 28 Mar 2012, Jukka Ruohonen wrote:
+ATF_TC_BODY(random_zero, tc)
+{
+       const size_t n = 1000000;
+       size_t i, j;
+       long x;
+
+       srandom(0);
+
+       for (i = j = 0; i < n; i++) {
+
+               if ((x = random()) == 0)
+                       j++;
+       }
+
+       ATF_REQUIRE(j != n);
+}

n=4 would probably be enough iterations, and I'd suggest requiring all
values to be different, rather than requiring at least one non-zero
value.

--apb (Alan Barrett)


Home | Main Index | Thread Index | Old Index