// Code is in the preload fn person_builder(first_name:&'static str, last_name: &'static str) -> Person { Person { first_name: first_name, last_name: last_name } }
// Code is in the preload- // Code is in the preload
- fn person_builder(first_name:&'static str, last_name: &'static str) -> Person {
- Person { first_name: first_name, last_name: last_name }
- }
#[test] fn can_build_a_person() { let p = person_builder("Jimbo", "Jones"); assert_eq!(p.greet(), "Hello, my name is Jimbo Jones"); } #[test] #[should_panic] fn failed_name() { let p = person_builder("Bill", "Smith"); assert_eq!(p.first_name, "Frank"); }
- #[test]
fn can_greet() {let p = Person { first_name: "Bill", last_name: "Smith" };assert_eq!(p.greet(), "Hello, my name is Bill Smith");- fn can_build_a_person() {
- let p = person_builder("Jimbo", "Jones");
- assert_eq!(p.greet(), "Hello, my name is Jimbo Jones");
- }
- #[test]
- #[should_panic]
- fn failed_name() {
- let p = person_builder("Bill", "Smith");
- assert_eq!(p.first_name, "Frank");
- }
Some thread of random rusty stuffsz
// Code is in the preload
#[test]
fn can_greet() {
let p = Person { first_name: "Bill", last_name: "Smith" };
assert_eq!(p.greet(), "Hello, my name is Bill Smith");
}
Updated to test that it is working with new rust changes
pub fn powermod(n: u64, p: u64, m: u64) -> u64 { if p == 0 { return 1 % m } if p == 1 { return n % m } let mut r = powermod(n, p / 2, m); r = r * r % m; if p & 1 == 1 { r = r * n % m; } r }
- pub fn powermod(n: u64, p: u64, m: u64) -> u64 {
- if p == 0 { return 1 % m }
- if p == 1 { return n % m }
- let mut r = powermod(n, p / 2, m);
- r = r * r % m;
- if p & 1 == 1 {
- r = r * n % m;
- }
- r
}#[test]fn test_powermod() {assert_eq!(powermod(2, 999999, 147), 50);- }
#[test] fn test_powermod() { assert_eq!(powermod(2, 999999, 147), 50); } #[test] #[should_panic] fn returns_expected() { assert_eq!("actual", "expected"); }
- #[test]
- fn test_powermod() {
- assert_eq!(powermod(2, 999999, 147), 50);
- }
- #[test]
- #[should_panic]
- fn returns_expected() {
- assert_eq!("actual", "expected");
- }
Passed and failing tests with imports etc
class Person { String firstName; String lastName; Person(this.firstName,this.lastName); String get fullName => '$firstName $lastName'; }
doubler(n) => n*2;- class Person {
- String firstName;
- String lastName;
- Person(this.firstName,this.lastName);
- String get fullName => '$firstName $lastName';
- }
test('Can create a new person', () { var p = new Person('Bill', 'Smith'); expect(p, new isInstanceOf<Person>()); }); test('Has firstName and lastName', () { var p = new Person('John', 'James'); expect(p.firstName, equals('John')); expect(p.lastName, equals('James')); }); test('Has fullName', () { var p = new Person('Jane', 'Doe'); expect(p.fullName, equals('Jane Doe')); }); test('Has age', () { expect(new Person('Bob','Frank').age, equals(23)); },skip: 'Testing if something can be skipped'); test('Can use async import', () async { var s = new Stream.fromIterable([1,2,3,4,5]); expect(await s.last, equals(5)); }); test('Can handle failed tests', () { expect(new Person('Bill','Smith').firstName,equals('John')); });
// Create your own tests here using the Test package (https://github.com/dart-lang/test)// Here is some boilerplate:test('Can double stuffs', () {expect(doubler(10), equals(20)) // Semicolon is missing here- test('Can create a new person', () {
- var p = new Person('Bill', 'Smith');
- expect(p, new isInstanceOf<Person>());
- });
- test('Has firstName and lastName', () {
- var p = new Person('John', 'James');
- expect(p.firstName, equals('John'));
- expect(p.lastName, equals('James'));
- });
- test('Has fullName', () {
- var p = new Person('Jane', 'Doe');
- expect(p.fullName, equals('Jane Doe'));
- });
- test('Has age', () {
- expect(new Person('Bob','Frank').age, equals(23));
- },skip: 'Testing if something can be skipped');
- test('Can use async import', () async {
- var s = new Stream.fromIterable([1,2,3,4,5]);
- expect(await s.last, equals(5));
- });
- test('Can handle failed tests', () {
- expect(new Person('Bill','Smith').firstName,equals('John'));
- });
For some reason I keep using this function as a test in all the runner changes
fn doubler(n:i32) -> i32 {
n * 2
}
#[test]
fn can_double() {
assert_eq!(doubler(23), 42);
}
#[test]
fn can_also_double() {
assert_eq!(doubler(23), 46);
}
#[test]
fn can_also_not_double() {
assert_eq!(doubler(23), 4);
}
Undefined is returned in this example where a semicolon is missing on the test
// Create your own tests here using the Test package (https://github.com/dart-lang/test) // Here is some boilerplate: test('Can double stuffs', () { expect(doubler(10), equals(20)) // Semicolon is missing here });
- // Create your own tests here using the Test package (https://github.com/dart-lang/test)
- // Here is some boilerplate:
test('Should be able use the preload fibonacci function', () {expect(fibonacci(20), equals(6765));- test('Can double stuffs', () {
- expect(doubler(10), equals(20)) // Semicolon is missing here
- });
test('Can randomly call the doubler function as well', () {expect(doubler(fibonacci(20)), equals(13530));});
Provides fibonacci
function, taken from Dart Pad sample in preload
// Create your own tests here using the Test package (https://github.com/dart-lang/test) // Here is some boilerplate: test('Should be able use the preload fibonacci function', () { expect(fibonacci(20), equals(6765)); }); test('Can randomly call the doubler function as well', () { expect(doubler(fibonacci(20)), equals(13530)); });
- // Create your own tests here using the Test package (https://github.com/dart-lang/test)
- // Here is some boilerplate:
test('Should be able to see stream var', () {expect(nums, new isInstanceOf<Stream>());- test('Should be able use the preload fibonacci function', () {
- expect(fibonacci(20), equals(6765));
- });
test('Should be able to await the streams ints', () async {expect(await nums.toList(), equals([1,2,3,4,5]));});- test('Can randomly call the doubler function as well', () {
- expect(doubler(fibonacci(20)), equals(13530));
- });
Uses async library import in the preload
Stream nums = new Stream.fromIterable([1,2,3,4,5]);
class Person {String firstName;String lastName;Person(this.firstName,this.lastName);}- Stream nums = new Stream.fromIterable([1,2,3,4,5]);
// Create your own tests here using the Test package (https://github.com/dart-lang/test) // Here is some boilerplate: test('Should be able to see stream var', () { expect(nums, new isInstanceOf<Stream>()); }); test('Should be able to await the streams ints', () async { expect(await nums.toList(), equals([1,2,3,4,5])); });
- // Create your own tests here using the Test package (https://github.com/dart-lang/test)
- // Here is some boilerplate:
test('Should be able to create a Person object', () {expect(new Person('Bill', 'Smith'), new isInstanceOf<Person>());- test('Should be able to see stream var', () {
- expect(nums, new isInstanceOf<Stream>());
- });
test('Person object has expected name', () {var p = new Person('Bill', 'Smith');expect(p.firstName, equals('Bill'));expect(p.lastName, equals('Smith'));- test('Should be able to await the streams ints', () async {
- expect(await nums.toList(), equals([1,2,3,4,5]));
- });
Contains random dart tests
class Person {
String firstName;
String lastName;
Person(this.firstName,this.lastName);
}
// Create your own tests here using the Test package (https://github.com/dart-lang/test)
// Here is some boilerplate:
test('Should be able to create a Person object', () {
expect(new Person('Bill', 'Smith'), new isInstanceOf<Person>());
});
test('Person object has expected name', () {
var p = new Person('Bill', 'Smith');
expect(p.firstName, equals('Bill'));
expect(p.lastName, equals('Smith'));
});
Test of the codewars array test case
var array = ['codewars'];
// Create your own tests here using the Test package (https://github.com/dart-lang/test)
// Here is some boilerplate:
test('The array should not be empty', () {
expect(array.length, greaterThan(0));
expect(array.length, equals(1));
expect(array[0], equals('codewars'));
});