Fixed fmt!, tests, doc-tests.

This commit is contained in:
Marvin Löbel 2013-02-02 16:40:42 +01:00 committed by Brian Anderson
parent 98445d95d4
commit af4972f3ce
7 changed files with 31 additions and 25 deletions

View File

@ -844,7 +844,7 @@ mod quux {
pub fn bar() { }
pub fn baz() { }
}
pub use quux::foo::*;
}
~~~~
@ -1242,7 +1242,7 @@ trait Num {
impl float: Num {
static pure fn from_int(n: int) -> float { n as float }
}
let x: float = Num::from_int(42);
let x: float = Num::from_int(42);
~~~~
Traits may inherit from other traits. For example, in
@ -1615,7 +1615,7 @@ The following are examples of structure expressions:
~~~~
# struct Point { x: float, y: float }
# struct TuplePoint(float, float);
# mod game { pub struct User { name: &str, age: uint, mut score: uint } }
# mod game { pub struct User { name: &str, age: uint, mut score: uint } }
# use game;
Point {x: 10f, y: 20f};
TuplePoint(10f, 20f);
@ -2812,7 +2812,7 @@ trait Printable {
}
impl int: Printable {
fn to_str() -> ~str { int::to_str(self, 10) }
fn to_str() -> ~str { int::to_str(self) }
}
fn print(a: @Printable) {

View File

@ -473,7 +473,7 @@ fn stringifier(channel: &DuplexStream<~str, uint>) {
let mut value: uint;
loop {
value = channel.recv();
channel.send(uint::to_str(value, 10));
channel.send(uint::to_str(value));
if value == 0 { break; }
}
}
@ -497,7 +497,7 @@ Here is the code for the parent task:
# let mut value: uint;
# loop {
# value = channel.recv();
# channel.send(uint::to_str(value, 10u));
# channel.send(uint::to_str(value));
# if value == 0u { break; }
# }
# }

View File

@ -422,6 +422,12 @@ pub pure fn to_str_bytes_common<T: Num Zero One Eq Ord Round Copy>(
buf = buf.slice(0, i + 1);
}
}
} // If exact and trailing '.', just cut that
else {
let max_i = buf.len() - 1;
if buf[max_i] == '.' as u8 {
buf = buf.slice(0, max_i);
}
}
(buf, false)
@ -678,4 +684,4 @@ pub pure fn from_str_common<T: Num Zero One Ord Copy>(
) -> Option<T> {
from_str_bytes_common(str::to_bytes(buf), radix, negative,
fractional, special, exponent, empty_zero)
}
}

View File

@ -926,7 +926,7 @@ mod tests {
let s0 = precise_time_s();
let ns1 = precise_time_ns();
log(debug, ~"s0=" + float::to_str(s0, 9u) + ~" sec");
log(debug, ~"s0=" + float::to_str_digits(s0, 9u) + ~" sec");
assert s0 > 0.;
let ns0 = (s0 * 1000000000.) as u64;
log(debug, ~"ns0=" + u64::str(ns0) + ~" ns");

View File

@ -75,12 +75,12 @@ fn old_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) {
let map = map::HashMap();
do timed(&mut results.sequential_strings) {
for uint::range(0, num_keys) |i| {
let s = uint::to_str(i, 10);
let s = uint::to_str(i);
map.insert(s, i);
}
for uint::range(0, num_keys) |i| {
let s = uint::to_str(i, 10);
let s = uint::to_str(i);
assert map.get(s) == i;
}
}
@ -90,7 +90,7 @@ fn old_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) {
let map = map::HashMap();
do timed(&mut results.random_strings) {
for uint::range(0, num_keys) |i| {
let s = uint::to_str(rng.next() as uint, 10);
let s = uint::to_str(rng.next() as uint);
map.insert(s, i);
}
}
@ -99,11 +99,11 @@ fn old_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) {
{
let map = map::HashMap();
for uint::range(0, num_keys) |i| {
map.insert(uint::to_str(i, 10), i);
map.insert(uint::to_str(i), i);
}
do timed(&mut results.delete_strings) {
for uint::range(0, num_keys) |i| {
assert map.remove(uint::to_str(i, 10));
assert map.remove(uint::to_str(i));
}
}
}
@ -151,12 +151,12 @@ fn linear_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results)
let mut map = LinearMap::new();
do timed(&mut results.sequential_strings) {
for uint::range(0, num_keys) |i| {
let s = uint::to_str(i, 10);
let s = uint::to_str(i);
map.insert(s, i);
}
for uint::range(0, num_keys) |i| {
let s = uint::to_str(i, 10);
let s = uint::to_str(i);
assert map.find(&s).unwrap() == &i;
}
}
@ -166,7 +166,7 @@ fn linear_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results)
let mut map = LinearMap::new();
do timed(&mut results.random_strings) {
for uint::range(0, num_keys) |i| {
let s = uint::to_str(rng.next() as uint, 10);
let s = uint::to_str(rng.next() as uint);
map.insert(s, i);
}
}
@ -175,11 +175,11 @@ fn linear_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results)
{
let mut map = LinearMap::new();
for uint::range(0, num_keys) |i| {
map.insert(uint::to_str(i, 10), i);
map.insert(uint::to_str(i), i);
}
do timed(&mut results.delete_strings) {
for uint::range(0, num_keys) |i| {
assert map.remove(&uint::to_str(i, 10));
assert map.remove(&uint::to_str(i));
}
}
}
@ -227,12 +227,12 @@ fn tree_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) {
let mut map = TreeMap::new();
do timed(&mut results.sequential_strings) {
for uint::range(0, num_keys) |i| {
let s = uint::to_str(i, 10);
let s = uint::to_str(i);
map.insert(s, i);
}
for uint::range(0, num_keys) |i| {
let s = uint::to_str(i, 10);
let s = uint::to_str(i);
assert map.find(&s).unwrap() == &i;
}
}
@ -242,7 +242,7 @@ fn tree_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) {
let mut map = TreeMap::new();
do timed(&mut results.random_strings) {
for uint::range(0, num_keys) |i| {
let s = uint::to_str(rng.next() as uint, 10);
let s = uint::to_str(rng.next() as uint);
map.insert(s, i);
}
}
@ -251,11 +251,11 @@ fn tree_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) {
{
let mut map = TreeMap::new();
for uint::range(0, num_keys) |i| {
map.insert(uint::to_str(i, 10), i);
map.insert(uint::to_str(i), i);
}
do timed(&mut results.delete_strings) {
for uint::range(0, num_keys) |i| {
assert map.remove(&uint::to_str(i, 10));
assert map.remove(&uint::to_str(i));
}
}
}

View File

@ -21,7 +21,7 @@ fn main() {
let n = uint::from_str(args[1]).get();
for uint::range(0u, n) |i| {
let x = uint::to_str(i, 10u);
let x = uint::to_str(i);
log(debug, x);
}
}

View File

@ -14,5 +14,5 @@ pub fn main() {
let digits: uint = 10 as uint;
::core::io::println(float::to_str(f64::sqrt(42.0f64) as float, digits));
::core::io::println(float::to_str_digits(f64::sqrt(42.0f64) as float, digits));
}