Updated test #64

This commit is contained in:
2026-06-05 20:06:38 +02:00
parent a9eb77f158
commit 8c28e61e42
13 changed files with 836 additions and 15 deletions
+39
View File
@@ -0,0 +1,39 @@
trait Speak {
fn speak(*self) String;
}
trait Greet : Speak {
fn greet(*self) String;
}
struct Dog {
name String,
}
impl Speak for Dog {
fn speak(*self) String {
"woof".to_string()
}
}
impl Greet for Dog {
fn greet(*self) String {
"hello".to_string()
}
}
pub fn test_trait_impl() {
let d = Dog { name: "Rex".to_string() };
assert_eq!(d.speak(), "woof");
}
pub fn test_trait_with_requirement() {
let d = Dog { name: "Buddy".to_string() };
assert_eq!(d.speak(), "woof");
assert_eq!(d.greet(), "hello");
}
pub fn run_tests() {
test_trait_impl();
test_trait_with_requirement();
}