Move func "constraints_default_clients_in_master" to Rust
This commit is contained in:
parent
098a5bc54c
commit
5e564e7903
|
@ -1,7 +1,5 @@
|
|||
#include "constraints.h"
|
||||
|
||||
#define MIN_DEFAULT_CLIENTS_IN_MASTER 1
|
||||
#define MAX_DEFAULT_CLIENTS_IN_MASTER 10000
|
||||
#define MIN_DEFAULT_MASTER_AREA_FACTOR 0.05
|
||||
#define MAX_DEFAULT_MASTER_AREA_FACTOR 0.95
|
||||
#define MIN_GAP_SIZE 0
|
||||
|
@ -13,13 +11,6 @@
|
|||
#define MIN_SNAP_DISTANCE 1
|
||||
#define MAX_SNAP_DISTANCE 10000
|
||||
|
||||
int constraints_default_clients_in_master(const int default_clients_in_master)
|
||||
{
|
||||
if (default_clients_in_master < MIN_DEFAULT_CLIENTS_IN_MASTER) return MIN_DEFAULT_CLIENTS_IN_MASTER;
|
||||
if (default_clients_in_master > MAX_DEFAULT_CLIENTS_IN_MASTER) return MAX_DEFAULT_CLIENTS_IN_MASTER;
|
||||
return default_clients_in_master;
|
||||
}
|
||||
|
||||
float constraints_default_master_area_factor(const float default_master_area_factor)
|
||||
{
|
||||
return constraints_master_area_factor(default_master_area_factor);
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
use std::os::raw::*;
|
||||
|
||||
const MAX_BORDER_WIDTH: c_int = 10000;
|
||||
const MIN_DEFAULT_CLIENTS_IN_MASTER: c_int = 1;
|
||||
const MAX_DEFAULT_CLIENTS_IN_MASTER: c_int = 10000;
|
||||
|
||||
pub fn border_width(border_width: c_int) -> c_int {
|
||||
if border_width > MAX_BORDER_WIDTH { return MAX_BORDER_WIDTH }
|
||||
border_width
|
||||
}
|
||||
|
||||
pub fn default_clients_in_master(default_clients_in_master: c_int) -> c_int {
|
||||
if default_clients_in_master < MIN_DEFAULT_CLIENTS_IN_MASTER {
|
||||
return MIN_DEFAULT_CLIENTS_IN_MASTER
|
||||
}
|
||||
if default_clients_in_master > MAX_DEFAULT_CLIENTS_IN_MASTER {
|
||||
return MAX_DEFAULT_CLIENTS_IN_MASTER
|
||||
}
|
||||
default_clients_in_master
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -20,4 +32,17 @@ mod tests {
|
|||
assert_eq!(border_width(10_001), 10_000);
|
||||
assert_eq!(border_width(20_000), 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_clients_in_master() {
|
||||
assert_eq!(default_clients_in_master(0), 1);
|
||||
|
||||
assert_eq!(default_clients_in_master(1), 1);
|
||||
assert_eq!(default_clients_in_master(2), 2);
|
||||
assert_eq!(default_clients_in_master(9999), 9999);
|
||||
assert_eq!(default_clients_in_master(10_000), 10_000);
|
||||
|
||||
assert_eq!(default_clients_in_master(10_001), 10_000);
|
||||
assert_eq!(default_clients_in_master(20_000), 10_000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,3 +6,8 @@ use std::os::raw::*;
|
|||
extern "C" fn constraints_border_width(border_width: c_int) -> c_int {
|
||||
constraints::border_width(border_width)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_default_clients_in_master(default_clients_in_master: c_int) -> c_int {
|
||||
constraints::default_clients_in_master(default_clients_in_master)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue