diff --git a/Cargo.toml b/Cargo.toml index 4ad9b88f5f..d55e9210ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -472,8 +472,3 @@ default-features = true version = "~0.3.0" path = "module/test/c" default-features = true - - -[patch.crates-io] -pathfinder_geometry = { git = "https://github.com/servo/pathfinder.git" } -pathfinder_simd = { git = "https://github.com/servo/pathfinder.git" } diff --git a/module/core/proper_path_tools/src/path.rs b/module/core/proper_path_tools/src/path.rs index b0c0308d8b..81af7d961e 100644 --- a/module/core/proper_path_tools/src/path.rs +++ b/module/core/proper_path_tools/src/path.rs @@ -357,6 +357,84 @@ pub( crate ) mod private vec![] } + + + + + /// Extracts the parent directory and file stem (without extension) from the given path. + /// + /// This function takes a path and returns an Option containing the modified path without the extension. + /// If the input path is empty or if it doesn't contain a file stem, it returns None. + /// + /// # Arguments + /// + /// * `path` - An object that can be converted into a Path reference, representing the file path. + /// + /// # Returns + /// + /// An Option containing the modified path without the extension, or None if the input path is empty or lacks a file stem. + /// + /// # Examples + /// + /// ``` + /// use std::path::PathBuf; + /// use proper_path_tools::path::without_ext; + /// + /// let path = "/path/to/file.txt"; + /// let modified_path = without_ext(path); + /// assert_eq!(modified_path, Some(PathBuf::from("/path/to/file"))); + /// ``` + /// + /// ``` + /// use std::path::PathBuf; + /// use proper_path_tools::path::without_ext; + /// + /// let empty_path = ""; + /// let modified_path = without_ext(empty_path); + /// assert_eq!(modified_path, None); + /// ``` + /// + pub fn without_ext( path : impl AsRef< std::path::Path > ) -> Option< std::path::PathBuf > + { + use std::path::Path; + use std::path::PathBuf; + + if path.as_ref().to_string_lossy().is_empty() + { + return None; + } + + let path_buf = Path::new( path.as_ref() ); + + let parent = match path_buf.parent() + { + Some( parent ) => parent, + None => return None, + }; + let file_stem = match path_buf.file_stem() + { + Some( name ) => + { + let ends = format!( "{}/", name.to_string_lossy() ); + if path.as_ref().to_string_lossy().ends_with( &ends ) + { + ends + } + else + { + String::from( name.to_string_lossy() ) + } + + } + None => return None, + }; + + let mut full_path = parent.to_path_buf(); + full_path.push( file_stem ); + + Some( PathBuf::from( full_path.to_string_lossy().replace( "\\", "/" ) ) ) + } + /// Finds the common directory path among a collection of paths. /// /// Given an iterator of path strings, this function determines the common directory @@ -796,6 +874,7 @@ crate::mod_interface! protected use path_relative; protected use rebase; protected use path_common; + protected use without_ext; protected use is_glob; protected use normalize; protected use canonicalize; diff --git a/module/core/proper_path_tools/tests/inc/mod.rs b/module/core/proper_path_tools/tests/inc/mod.rs index 016f3508e9..4107e22677 100644 --- a/module/core/proper_path_tools/tests/inc/mod.rs +++ b/module/core/proper_path_tools/tests/inc/mod.rs @@ -6,6 +6,7 @@ mod path_is_glob; mod absolute_path; mod path_exts; mod path_ext; +mod without_ext; mod path_common; mod rebase_path; mod path_relative; diff --git a/module/core/proper_path_tools/tests/inc/without_ext.rs b/module/core/proper_path_tools/tests/inc/without_ext.rs new file mode 100644 index 0000000000..fa1c5bf11e --- /dev/null +++ b/module/core/proper_path_tools/tests/inc/without_ext.rs @@ -0,0 +1,114 @@ +#[ allow( unused_imports ) ] +use super::*; + +#[ test ] +fn empty_path() +{ + let path = ""; + let expected = None; + assert_eq!( the_module::path::without_ext( path ), expected ); +} + +#[ test ] +fn txt_extension() +{ + let path = "some.txt"; + let expected = "some"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn path_with_non_empty_dir_name() +{ + let path = "/foo/bar/baz.asdf"; + let expected = "/foo/bar/baz"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn hidden_file() +{ + let path = "/foo/bar/.baz"; + let expected = "/foo/bar/.baz"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn file_with_composite_file_name() +{ + let path = "/foo.coffee.md"; + let expected = "/foo.coffee"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn path_without_extension() +{ + let path = "/foo/bar/baz"; + let expected = "/foo/bar/baz"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn relative_path_1() +{ + let path = "./foo/.baz"; + let expected = "./foo/.baz"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn relative_path_2() +{ + let path = "./.baz"; + let expected = "./.baz"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn relative_path_3() +{ + let path = ".baz.txt"; + let expected = ".baz"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn relative_path_4() +{ + let path = "./baz.txt"; + let expected = "./baz"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn relative_path_5() +{ + let path = "./foo/baz.txt"; + let expected = "./foo/baz"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn relative_path_6() +{ + let path = "./foo/"; + let expected = "./foo/"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn relative_path_7() +{ + let path = "baz"; + let expected = "baz"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} + +#[ test ] +fn relative_path_8() +{ + let path = "baz.a.b"; + let expected = "baz.a"; + assert_eq!( the_module::path::without_ext( path ).unwrap().to_string_lossy(), expected ); +} \ No newline at end of file diff --git a/module/move/optimization_tools/.cargo/config.toml b/module/move/optimization_tools/.cargo/config.toml new file mode 100644 index 0000000000..ce93c42ac4 --- /dev/null +++ b/module/move/optimization_tools/.cargo/config.toml @@ -0,0 +1,3 @@ +[patch.crates-io] +pathfinder_geometry = { git = "https://github.com/servo/pathfinder.git" } +pathfinder_simd = { git = "https://github.com/servo/pathfinder.git" } \ No newline at end of file diff --git a/module/move/optimization_tools/Cargo.toml b/module/move/optimization_tools/Cargo.toml index a9fb722248..3c8e802a8a 100644 --- a/module/move/optimization_tools/Cargo.toml +++ b/module/move/optimization_tools/Cargo.toml @@ -33,8 +33,8 @@ full = [ enabled = [] rapidity_6 = [] # to enable slow tests static_plot = [] -dynamic_plot = [ "static_plot", "plotters-backend", "piston_window" ] -lp_parse = [ "exmex" ] +dynamic_plot = [ "static_plot", "dep:plotters-backend", "dep:piston_window" ] +lp_parse = [ "dep:exmex" ] [dependencies] derive_tools = { workspace = true, features = [ "derive_more", "full", "strum" ] } diff --git a/module/move/optimization_tools/src/problems/sudoku/sudoku.rs b/module/move/optimization_tools/src/problems/sudoku/sudoku.rs index 26b83e8e7b..b016fa4cda 100644 --- a/module/move/optimization_tools/src/problems/sudoku/sudoku.rs +++ b/module/move/optimization_tools/src/problems/sudoku/sudoku.rs @@ -12,28 +12,11 @@ use iter_tools::Itertools; trait BoardExt { /// Validate that each bloack has at least one non-fixed cell. - fn validate_each_block_has_non_fixed_cell( &self ) -> bool; fn validate_block_has_non_fixed_cells( &self, block : BlockIndex ) -> bool; } impl BoardExt for Board { - fn validate_each_block_has_non_fixed_cell( &self ) -> bool - { - for block in self.blocks() - { - let fixed = self.block_cells( block ) - .map( | cell | self.cell( cell ) ) - .fold( 0, | acc, e | if e == 0.into() { acc + 1 } else { acc } ) - ; - if fixed <= 1 || fixed >= 10 - { - return false; - } - } - true - } - fn validate_block_has_non_fixed_cells( &self, block : BlockIndex ) -> bool { let fixed = self.block_cells( block ) diff --git a/module/move/optimization_tools/tests/ga_optimization.rs b/module/move/optimization_tools/tests/ga_optimization.rs index cd51e39772..a4cf4d8b2d 100644 --- a/module/move/optimization_tools/tests/ga_optimization.rs +++ b/module/move/optimization_tools/tests/ga_optimization.rs @@ -57,6 +57,7 @@ fn crossover() /// cargo test solve_with_ga --release --features rapidity_6 /// #[ cfg( feature = "rapidity_6" ) ] +#[ ignore ] #[ test ] fn solve_with_ga() { diff --git a/module/move/optimization_tools/tests/optimization.rs b/module/move/optimization_tools/tests/optimization.rs index a5540bcab1..dd50054eb2 100644 --- a/module/move/optimization_tools/tests/optimization.rs +++ b/module/move/optimization_tools/tests/optimization.rs @@ -61,6 +61,7 @@ fn initial_temperature() /// cargo test solve_with_sa --release --features rapidity_6 /// #[ cfg( feature = "rapidity_6" ) ] +#[ ignore ] #[ test ] fn solve_with_sa() { @@ -106,6 +107,7 @@ fn solve_with_sa() /// cargo test solve_empty_full_block --release --features rapidity_6 /// #[ cfg( feature = "rapidity_6" ) ] +#[ ignore ] #[ test ] fn solve_empty_full_block() { @@ -182,6 +184,7 @@ fn solve_empty_full_block() /// cargo test time_measure --release --features rapidity_6 /// #[ cfg( feature = "rapidity_6" ) ] +#[ ignore ] #[ test ] fn time_measure() { diff --git a/module/move/optimization_tools/tests/traveling_salesman.rs b/module/move/optimization_tools/tests/traveling_salesman.rs index 0b8d618a4e..513a1a86c9 100644 --- a/module/move/optimization_tools/tests/traveling_salesman.rs +++ b/module/move/optimization_tools/tests/traveling_salesman.rs @@ -82,6 +82,7 @@ fn tsp_person_mutate() a_id!( person.route.len() - 1, unique.len() ); } +#[ ignore ] #[ test ] fn find_route() {