From 82dbc2ea619cbfc98ca9ad2f9e06a5acd294cbe3 Mon Sep 17 00:00:00 2001 From: Robin Kruppe Date: Sun, 26 Jul 2015 15:24:08 +0200 Subject: Add optional, external tests for floating point parsing. Running these tests takes hours, so they are not run by @bors. --- src/etc/test-float-parse/many-digits.rs | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/etc/test-float-parse/many-digits.rs (limited to 'src/etc/test-float-parse/many-digits.rs') diff --git a/src/etc/test-float-parse/many-digits.rs b/src/etc/test-float-parse/many-digits.rs new file mode 100644 index 00000000000..0cbf57183df --- /dev/null +++ b/src/etc/test-float-parse/many-digits.rs @@ -0,0 +1,39 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rand)] + +extern crate rand; + +mod _common; + +use std::char; +use rand::{IsaacRng, Rng, SeedableRng}; +use rand::distributions::{Range, Sample}; +use _common::{validate, SEED}; + +fn main() { + let mut rnd = IsaacRng::from_seed(&SEED); + let mut range = Range::new(0, 10); + for _ in 0..5_000_000u64 { + let num_digits = rnd.gen_range(100, 300); + let digits = gen_digits(num_digits, &mut range, &mut rnd); + validate(digits); + } +} + +fn gen_digits(n: u32, range: &mut Range, rnd: &mut R) -> String { + let mut s = String::new(); + for _ in 0..n { + let digit = char::from_digit(range.sample(rnd), 10).unwrap(); + s.push(digit); + } + s +} -- cgit 1.4.1-3-g733a5