Skip to content

Commit

Permalink
tests moved to tests directory
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodesdev committed Jun 4, 2024
1 parent 433b6a4 commit 93834e4
Show file tree
Hide file tree
Showing 35 changed files with 23 additions and 57 deletions.
2 changes: 0 additions & 2 deletions challenges/character-counting-string/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn count_characters(s: &str) -> u32 {
s.chars().count() as u32
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::count_characters;
use character_counting_string::*;

#[test]
fn should_count_characters() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/countdown/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn countdown(n: u32) -> Vec<u32> {
let mut current = n;
let mut result = Vec::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::countdown;
use countdown::*;

#[test]
fn test_countdown() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/determine-number-characteristics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn describe_number(n: i32) -> String {
if n == 0 {
return String::from("Zero");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::describe_number;
use determine_number_characteristics::*;

#[test]
fn test_positive_even() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/factorial-calculator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn factorial(n: u32) -> u128 {
if n == 0 {
return 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::factorial;
use factorial_calculator::*;

#[test]
fn test_factorial_of_zero() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/fibonacci/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn fibonacci(n: u32) -> u32 {
match n {
0 => 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::fibonacci;
use fibonacci::*;

#[test]
fn zero() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/fizz-buzz/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn fizz_buzz(num: u32) -> String {
match (num % 3, num % 5) {
(0, 0) => "FizzBuzz".to_string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::fizz_buzz;
use fizz_buzz::*;

#[test]
fn should_return_fizz() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/graceful-error-handling/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn parse_percentage(input: &str) -> Result<u8, String> {
match input.parse::<u8>() {
Ok(percentage) if percentage <= 100 => Ok(percentage),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::parse_percentage;
use graceful_error_handling::*;

#[test]
fn test_parse_percentage_valid() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/hello-world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn hello_world() -> &'static str {
"Hello, World!"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::hello_world;
use hello_world::*;

#[test]
fn should_return_hello_world() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/if-else/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn is_even(n: i32) -> bool {
if n % 2 == 0 {
true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::is_even;
use if_else::*;

#[test]
fn test_is_even() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/is-prime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn is_prime(n: u32) -> bool {
if n < 2 {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::is_prime;
use is_prime::*;

#[test]
fn test_is_prime_small_numbers() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/mathematical-operations/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn math_operations(a: i32, b: i32) -> (i32, i32, i32, i32) {
(a + b, a - b, a * b, a / b)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::math_operations;
use mathematical_operations::*;

#[test]
fn math_tests() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/median-and-mode/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

use std::collections::HashMap;

pub fn median(numbers: &mut Vec<i32>) -> f32 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::{median, mode};
use median_and_mode::*;

#[test]
fn test_median() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/sum-of-even-numbers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn sum_of_evens(start: i32, end: i32) -> i32 {
if start > end {
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::sum_of_evens;
use sum_of_even_numbers::*;

#[test]
fn test_sum_of_evens_range() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/temperature-converter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn convert_temperature(value: f64, from_unit: &str, to_unit: &str) -> Result<f64, String> {
match (from_unit, to_unit) {
("C", "F") => Ok(value * 9.0 / 5.0 + 32.0),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::convert_temperature;
use temperature_converter::*;

#[test]
fn test_convert_celsius_to_fahrenheit() {
Expand Down
8 changes: 3 additions & 5 deletions challenges/the-from-trait/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod tests;

pub struct Minutes(i32);
pub struct Hours(i32);
pub struct Days(i32);
pub struct Minutes(pub i32);
pub struct Hours(pub i32);
pub struct Days(pub i32);

impl From<Minutes> for Hours {
fn from(minutes: Minutes) -> Hours {
Expand Down
6 changes: 3 additions & 3 deletions challenges/the-from-trait/src/starter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub struct Minutes(i32);
pub struct Hours(i32);
pub struct Days(i32);
pub struct Minutes(pub i32);
pub struct Hours(pub i32);
pub struct Days(pub i32);

impl From<Minutes> for Hours {
fn from(minutes: Minutes) -> Hours {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::{Days, Hours, Minutes};
use the_from_trait::*;

#[test]
fn should_convert_minutes_to_hours() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/validate-user-input/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn validate_user(age: i32, email: &str) -> Result<(), String> {
if age < 0 || age > 120 {
return Err(String::from("Invalid age"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::validate_user;
use validate_user_input::*;

#[test]
fn test_valid_user() {
Expand Down
2 changes: 0 additions & 2 deletions challenges/weekday-from-number/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod tests;

pub fn weekday_from_number(day: u8) -> &'static str {
match day {
1 => "Monday",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use crate::weekday_from_number;
use weekday_from_number::*;

#[test]
fn test_weekday_from_number_valid() {
Expand Down

0 comments on commit 93834e4

Please sign in to comment.