Require a main function in all exercises

This commit is contained in:
mo8it
2024-04-17 22:46:21 +02:00
parent d83cc69afe
commit cb9f1ac9ce
39 changed files with 199 additions and 44 deletions
+4
View File
@@ -10,6 +10,10 @@ pub fn bigger(a: i32, b: i32) -> i32 {
// - additional variables
}
fn main() {
// You can optionally experiment here.
}
// Don't mind this for now :)
#[cfg(test)]
mod tests {
+4
View File
@@ -13,6 +13,10 @@ pub fn foo_if_fizz(fizzish: &str) -> &str {
}
}
fn main() {
// You can optionally experiment here.
}
// No test changes needed!
#[cfg(test)]
mod tests {
+4
View File
@@ -27,6 +27,10 @@ pub fn animal_habitat(animal: &str) -> &'static str {
habitat
}
fn main() {
// You can optionally experiment here.
}
// No test changes needed.
#[cfg(test)]
mod tests {
@@ -5,6 +5,10 @@
// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand
// for a hint.
fn main() {
// You can optionally experiment here.
}
#[test]
fn slice_out_of_array() {
let a = [1, 2, 3, 4, 5];
@@ -6,6 +6,10 @@
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand
// for a hint.
fn main() {
// You can optionally experiment here.
}
#[test]
fn indexing_tuple() {
let numbers = (1, 2, 3);
+4
View File
@@ -14,6 +14,10 @@ fn array_and_vec() -> ([i32; 4], Vec<i32>) {
(a, v)
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -26,6 +26,10 @@ fn vec_map(v: &Vec<i32>) -> Vec<i32> {
}).collect()
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -14,6 +14,10 @@ struct ColorTupleStruct(/* TODO: Something goes here */);
#[derive(Debug)]
struct UnitLikeStruct;
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -28,6 +28,10 @@ fn create_order_template() -> Order {
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -38,6 +38,10 @@ impl Package {
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -45,6 +45,10 @@ impl State {
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -18,6 +18,10 @@ fn replace_me(input: &str) -> String {
???
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -24,6 +24,10 @@ fn fruit_basket() -> HashMap<String, u32> {
basket
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+5 -1
View File
@@ -41,6 +41,10 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
@@ -79,7 +83,7 @@ mod tests {
let count = basket.values().sum::<u32>();
assert!(count > 11);
}
#[test]
fn all_fruit_types_in_basket() {
let mut basket = get_fruit_basket();
+7 -3
View File
@@ -5,9 +5,9 @@
// Example: England,France,4,2 (England scored 4 goals, France 2).
//
// You have to build a scores table containing the name of the team, the total
// number of goals the team scored, and the total number of goals the team
// conceded. One approach to build the scores table is to use a Hashmap.
// The solution is partially written to use a Hashmap,
// number of goals the team scored, and the total number of goals the team
// conceded. One approach to build the scores table is to use a Hashmap.
// The solution is partially written to use a Hashmap,
// complete it to pass the test.
//
// Make me pass the tests!
@@ -42,6 +42,10 @@ fn build_scores_table(results: String) -> HashMap<String, Team> {
scores
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -14,6 +14,10 @@ fn maybe_icecream(time_of_day: u16) -> Option<u16> {
???
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -3,6 +3,10 @@
// Execute `rustlings hint options2` or use the `hint` watch subcommand for a
// hint.
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
#[test]
+4
View File
@@ -9,6 +9,10 @@
// Execute `rustlings hint errors1` or use the `hint` watch subcommand for a
// hint.
fn main() {
// You can optionally experiment here.
}
pub fn generate_nametag_text(name: String) -> Option<String> {
if name.is_empty() {
// Empty names aren't allowed.
+4
View File
@@ -29,6 +29,10 @@ pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
Ok(qty * cost_per_item + processing_fee)
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -19,6 +19,10 @@ impl PositiveNonzeroInteger {
}
}
fn main() {
// You can optionally experiment here.
}
#[test]
fn test_creation() {
assert!(PositiveNonzeroInteger::new(10).is_ok());
+4
View File
@@ -54,6 +54,10 @@ impl PositiveNonzeroInteger {
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod test {
use super::*;
+4
View File
@@ -16,6 +16,10 @@ impl Wrapper {
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -14,6 +14,10 @@ trait AppendBar {
// TODO: Implement trait `AppendBar` for a vector of strings.
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -23,6 +23,10 @@ struct OtherSoftware {
impl Licensed for SomeSoftware {} // Don't edit this line
impl Licensed for OtherSoftware {} // Don't edit this line
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -25,6 +25,10 @@ fn compare_license_types(software: ??, software_two: ??) -> bool {
software.licensing_info() == software_two.licensing_info()
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -10,6 +10,10 @@
// Execute `rustlings hint tests1` or use the `hint` watch subcommand for a
// hint.
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
#[test]
+4
View File
@@ -6,6 +6,10 @@
// Execute `rustlings hint tests2` or use the `hint` watch subcommand for a
// hint.
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
#[test]
+4
View File
@@ -11,6 +11,10 @@ pub fn is_even(num: i32) -> bool {
num % 2 == 0
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+6 -2
View File
@@ -7,7 +7,7 @@
struct Rectangle {
width: i32,
height: i32
height: i32,
}
impl Rectangle {
@@ -16,10 +16,14 @@ impl Rectangle {
if width <= 0 || height <= 0 {
panic!("Rectangle width and height cannot be negative!")
}
Rectangle {width, height}
Rectangle { width, height }
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -33,6 +33,10 @@ pub fn capitalize_words_string(words: &[&str]) -> String {
String::new()
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -43,6 +43,10 @@ fn list_of_results() -> () {
let division_results = numbers.into_iter().map(|n| divide(n, 27));
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -15,6 +15,10 @@ pub fn factorial(num: u64) -> u64 {
// Execute `rustlings hint iterators4` for hints.
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -55,6 +55,10 @@ fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Pr
todo!();
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -25,6 +25,10 @@ fn abs_all<'a, 'b>(input: &'a mut Cow<'b, [i32]>) -> &'a mut Cow<'b, [i32]> {
input
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -26,6 +26,10 @@ fn num_sq<T>(arg: &mut T) {
???
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
+4
View File
@@ -16,6 +16,10 @@
// Put your function here!
// fn calculate_price_of_apples {
fn main() {
// You can optionally experiment here.
}
// Don't modify this function!
#[test]
fn verify_test() {
+4
View File
@@ -40,6 +40,10 @@ mod my_module {
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
// TODO: What do we need to import to have `transformer` in scope?
+8 -2
View File
@@ -24,11 +24,17 @@ pub struct ReportCard {
impl ReportCard {
pub fn print(&self) -> String {
format!("{} ({}) - achieved a grade of {}",
&self.student_name, &self.student_age, &self.grade)
format!(
"{} ({}) - achieved a grade of {}",
&self.student_name, &self.student_age, &self.grade
)
}
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;