Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: test/cctest/test-strtod.cc

Issue 231443002: Improve reproducibility of test runs. (Closed) Base URL: git@github.com:v8/v8.git@master
Patch Set: Address nit Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/cctest/test-types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 16 matching lines...) Expand all
27 27
28 #include <stdlib.h> 28 #include <stdlib.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #include "bignum.h" 32 #include "bignum.h"
33 #include "cctest.h" 33 #include "cctest.h"
34 #include "diy-fp.h" 34 #include "diy-fp.h"
35 #include "double.h" 35 #include "double.h"
36 #include "strtod.h" 36 #include "strtod.h"
37 #include "utils/random-number-generator.h"
37 38
38 using namespace v8::internal; 39 using namespace v8::internal;
39 40
40 static Vector<const char> StringToVector(const char* str) { 41 static Vector<const char> StringToVector(const char* str) {
41 return Vector<const char>(str, StrLength(str)); 42 return Vector<const char>(str, StrLength(str));
42 } 43 }
43 44
44 45
45 static double StrtodChar(const char* str, int exponent) { 46 static double StrtodChar(const char* str, int exponent) {
46 return Strtod(StringToVector(str), exponent); 47 return Strtod(StringToVector(str), exponent);
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); 442 lo = 18273 * (lo & 0xFFFF) + (lo >> 16);
442 return (hi << 16) + (lo & 0xFFFF); 443 return (hi << 16) + (lo & 0xFFFF);
443 } 444 }
444 445
445 446
446 static const int kBufferSize = 1024; 447 static const int kBufferSize = 1024;
447 static const int kShortStrtodRandomCount = 2; 448 static const int kShortStrtodRandomCount = 2;
448 static const int kLargeStrtodRandomCount = 2; 449 static const int kLargeStrtodRandomCount = 2;
449 450
450 TEST(RandomStrtod) { 451 TEST(RandomStrtod) {
451 srand(static_cast<unsigned int>(time(NULL))); 452 RandomNumberGenerator rng;
452 char buffer[kBufferSize]; 453 char buffer[kBufferSize];
453 for (int length = 1; length < 15; length++) { 454 for (int length = 1; length < 15; length++) {
454 for (int i = 0; i < kShortStrtodRandomCount; ++i) { 455 for (int i = 0; i < kShortStrtodRandomCount; ++i) {
455 int pos = 0; 456 int pos = 0;
456 for (int j = 0; j < length; ++j) { 457 for (int j = 0; j < length; ++j) {
457 buffer[pos++] = rand() % 10 + '0'; 458 buffer[pos++] = rng.NextInt(10) + '0';
458 } 459 }
459 int exponent = DeterministicRandom() % (25*2 + 1) - 25 - length; 460 int exponent = DeterministicRandom() % (25*2 + 1) - 25 - length;
460 buffer[pos] = '\0'; 461 buffer[pos] = '\0';
461 Vector<const char> vector(buffer, pos); 462 Vector<const char> vector(buffer, pos);
462 double strtod_result = Strtod(vector, exponent); 463 double strtod_result = Strtod(vector, exponent);
463 CHECK(CheckDouble(vector, exponent, strtod_result)); 464 CHECK(CheckDouble(vector, exponent, strtod_result));
464 } 465 }
465 } 466 }
466 for (int length = 15; length < 800; length += 2) { 467 for (int length = 15; length < 800; length += 2) {
467 for (int i = 0; i < kLargeStrtodRandomCount; ++i) { 468 for (int i = 0; i < kLargeStrtodRandomCount; ++i) {
468 int pos = 0; 469 int pos = 0;
469 for (int j = 0; j < length; ++j) { 470 for (int j = 0; j < length; ++j) {
470 buffer[pos++] = rand() % 10 + '0'; 471 buffer[pos++] = rng.NextInt(10) + '0';
471 } 472 }
472 int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length; 473 int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length;
473 buffer[pos] = '\0'; 474 buffer[pos] = '\0';
474 Vector<const char> vector(buffer, pos); 475 Vector<const char> vector(buffer, pos);
475 double strtod_result = Strtod(vector, exponent); 476 double strtod_result = Strtod(vector, exponent);
476 CHECK(CheckDouble(vector, exponent, strtod_result)); 477 CHECK(CheckDouble(vector, exponent, strtod_result));
477 } 478 }
478 } 479 }
479 } 480 }
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698