Skip to content

Commit

Permalink
add test target for rusted
Browse files Browse the repository at this point in the history
  • Loading branch information
ognevny committed Jul 24, 2024
1 parent bd03916 commit d660366
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 52 deletions.
48 changes: 24 additions & 24 deletions dad-is-great-in-C/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')

add_project_arguments(
cc.get_supported_arguments('-fdiagnostics-color=always', '-pipe'),
language: 'c',
cc.get_supported_arguments('-fdiagnostics-color=always', '-pipe'),
language: 'c',
)

add_project_arguments(
cxx.get_supported_arguments(
'-Wno-c++98-compat-pedantic',
'-Wno-unsafe-buffer-usage',
'-Wno-poison-system-directories',
'-fdiagnostics-color=always',
'-pipe'
),
language: 'cpp',
cxx.get_supported_arguments(
'-Wno-c++98-compat-pedantic',
'-Wno-unsafe-buffer-usage',
'-Wno-poison-system-directories',
'-fdiagnostics-color=always',
'-pipe',
),
language: 'cpp',
)

src_c = [
'b_sort.cpp',
'firstword.cpp',
'hords.cpp',
'i_sort.cpp',
'lastword.cpp',
'longman.cpp',
'm_sort.cpp',
'middles.cpp',
'resheto.cpp',
's_sort.cpp',
'speedometer++.cpp',
'speedometer.c',
'tumba-umba.cpp',
'b_sort.cpp',
'firstword.cpp',
'hords.cpp',
'i_sort.cpp',
'lastword.cpp',
'longman.cpp',
'm_sort.cpp',
'middles.cpp',
'resheto.cpp',
's_sort.cpp',
'speedometer++.cpp',
'speedometer.c',
'tumba-umba.cpp',
]
foreach file : src_c
executable(file.split('.')[0], file)
executable(file.split('.')[0], file)
endforeach

if tests
Expand Down
49 changes: 32 additions & 17 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
project(
'ognevny-my-code',
version: '0.0.0',
meson_version: '>= 1.5.0',
default_options: [
'warning_level=everything',
'cpp_std=gnu++11,c++11',
'c_std=gnu11,c11',
'rust_std=2021',
'crossbeam-utils-0.8-rs:feature-default=true',
'aho-corasick-1-rs:feature-perf-literal=true',
],
license: 'WTFPL',
'ognevny-my-code',
version: '0.0.0',
meson_version: '>= 1.5.0',
default_options: [
'warning_level=everything',
'cpp_std=gnu++11,c++11',
'c_std=gnu11,c11',
'rust_std=2021',
'crossbeam-utils-0.8-rs:feature-default=true',
'aho-corasick-1-rs:feature-perf-literal=true',
],
license: 'WTFPL',
)

build_c = get_option('build_c_cpp')
Expand All @@ -20,15 +20,30 @@ build_all = get_option('build_all')
tests = get_option('tests')

if build_c or build_all
add_languages(['c', 'cpp'], native: false)
subdir('dad-is-great-in-C')
add_languages(['c', 'cpp'], native: false)
subdir('dad-is-great-in-C')
endif

if build_rust or build_all
add_languages(['rust'], native: false)
subproject('rusted')
add_languages(['rust'], native: false)
subproject('rusted')
if tests
custom_target(
'cargo-test',
build_by_default: true,
build_always_stale: true,
console: true,
output: 'rusted-tests',
command: [
find_program('cargo'),
'test',
'--manifest-path',
meson.project_source_root() / 'subprojects/rusted/Cargo.toml',
],
)
endif
endif

if build_py or build_all
subdir('pie')
subdir('pie')
endif
4 changes: 2 additions & 2 deletions subprojects/rusted/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "rusted"
version = "0.1.0"
edition = "2021"
rust-version = "1.65.0"

[dependencies]
itertools = "0.13"
Expand All @@ -18,6 +19,5 @@ meval = { git = "https://github.com/Titaniumtown/meval-rs" }
name = "rusted"
path = "src/lib.rs"
test = true
doctest = false
doc = true
proc-macro = false
edition = "2021"
55 changes: 46 additions & 9 deletions subprojects/rusted/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub mod ege1 {
use std::fs;

/// the first code with tasks from EGE exam
pub fn ex1() -> Result<usize, Box<dyn std::error::Error>> {
let text = fs::read_to_string("11.txt")?;
pub fn ex1() -> usize {
let text = fs::read_to_string("11.txt").unwrap();
let newtext = text.replace("INFINITY", "@");
let mut pos = Vec::new();
for (i, char) in newtext.chars().enumerate() {
Expand All @@ -17,16 +17,16 @@ pub mod ege1 {
for i in 0..(pos.len() - 1001) {
mx = mx.max(pos[i + 1001] - pos[i] - 1 + 7000 + 14);
}
Ok(mx)
mx
}

#[cfg(test)]
mod tests {
use crate::*;
use super::ex1;

#[test]
fn test_all() {
let ex1 = ex1().unwrap();
let ex1 = ex1();
assert_eq!(ex1, 36747);
}
}
Expand All @@ -39,6 +39,18 @@ pub mod first_word {
.map_or_else(|| input.trim(), |n| input[..n].trim())
.to_owned()
}

#[cfg(test)]
mod tests {
use super::first_word;

#[test]
fn test_all() {
assert_eq!(first_word("hello world "), "hello");
assert_eq!(first_word(" no"), "");
assert_eq!(first_word("coffee of tea"), "coffee");
}
}
}

pub mod integral {
Expand Down Expand Up @@ -163,6 +175,18 @@ pub mod last_word {
input[n + 1..].trim().to_owned()
})
}

#[cfg(test)]
mod tests {
use super::last_word;

#[test]
fn test_all() {
assert_eq!(last_word("hello world "), "world");
assert_eq!(last_word(" no"), "no");
assert_eq!(last_word("coffee of tea"), "tea");
}
}
}

pub mod longman {
Expand All @@ -184,6 +208,7 @@ pub mod longman2 {

/// find a maximum HEX number in string
pub fn longman2(data: &str) -> String {
assert!(data.is_ascii(), "non-ASCII characters are not allowed");
let nums: Vec<String> = data
.chars()
.fold((String::new(), vec![]), |(mut word, mut nums), char| {
Expand All @@ -204,6 +229,16 @@ pub mod longman2 {
.max_by_key(|num| usize::from_str_radix(num, 16).unwrap())
.unwrap()
}

#[cfg(test)]
mod tests {
use super::longman2;

#[test]
fn test_all() {
assert_eq!(longman2("af5Y3d"), "af5");
}
}
}

pub mod mask1 {
Expand All @@ -219,7 +254,7 @@ pub mod mask1 {

#[cfg(test)]
mod tests {
use crate::*;
use super::fn_match;

#[test]
fn test_all() {
Expand Down Expand Up @@ -370,7 +405,7 @@ pub mod mcko {

#[cfg(test)]
mod tests {
use crate::*;
use super::*;

#[test]
fn test_all() {
Expand Down Expand Up @@ -432,7 +467,7 @@ pub mod probnik {

#[cfg(test)]
mod tests {
use crate::*;
use super::probnik;

#[test]
fn test_all() {
Expand Down Expand Up @@ -550,7 +585,7 @@ pub mod speedometer {
#[inline]
#[allow(dead_code)]
const fn s() -> u32 {
pub const fn s() -> u32 {
let mut n = 1;
while n < 1_000_000_000 {
n += 1;
Expand All @@ -560,6 +595,8 @@ pub mod speedometer {

#[cfg(test)]
mod tests {
use super::s;

#[test]
fn print() {
print!("{}", s())
Expand Down

0 comments on commit d660366

Please sign in to comment.