Skip to content

Commit

Permalink
ready
Browse files Browse the repository at this point in the history
  • Loading branch information
SRetip committed Mar 26, 2024
1 parent 7304d1f commit 46572e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
18 changes: 5 additions & 13 deletions module/move/willbe/src/entity/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ mod private
Ok( features_powerset )
}

/// Calculate estimate for `features_powerset.length`
pub fn estimate_with
(
n : usize,
Expand All @@ -109,7 +110,8 @@ mod private
with_none_features : bool,
enabled_features : &[ String ],
total_features : usize
) -> usize
)
-> usize
{
let mut estimate = 0;
let mut binom = 1;
Expand Down Expand Up @@ -141,22 +143,12 @@ mod private

estimate
}

// fn factorial( n : usize ) -> Result< usize >
// {
// return if n <= 1
// {
// Ok( 1 )
// }
// else
// {
// n.checked_mul( factorial( n - 1 )? ).ok_or_else( || err!( "Too big value" ) )
// }
// }

}

crate::mod_interface!
{
/// Features
protected use features_powerset;
protected use estimate_with;
}
11 changes: 11 additions & 0 deletions module/move/willbe/tests/inc/entity/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use the_module::features::features_powerset;
use std::collections::HashMap;
use serde::Deserialize;
use the_module::workspace::WorkspacePackage;
use willbe::features::estimate_with;

/// Constructs a mock `Package` with specified features for testing.
fn mock_package( features : Vec< ( &str, Vec< &str > ) > ) -> WorkspacePackage
Expand Down Expand Up @@ -254,4 +255,14 @@ fn case_6()
assert!( result.contains( &vec![ "f2".to_string() ].into_iter().collect()) );

assert_eq!( result.len(), 2 );
}

#[ test ]
fn estimate()
{
assert_eq!( estimate_with( 5, 2, false, false, &[], 0 ), 16 );
assert_eq!( estimate_with( 5, 2, true, false, &[], 0 ), 17 );
assert_eq!( estimate_with( 5, 2, false, true, &[], 0 ), 17 );
assert_eq!( estimate_with( 5, 2, false, false, &[ "feature1".to_string(), "feature2".to_string() ], 2 ), 20 );
assert_eq!( estimate_with( 5, 2, true, true, &[ "feature1".to_string(), "feature2".to_string() ], 2 ), 22 );
}

0 comments on commit 46572e1

Please sign in to comment.