-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: better architecture for differ library
fixes #36
- Loading branch information
1 parent
827a1e5
commit 8e7d892
Showing
7 changed files
with
369 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::StringDiffOp; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Diff { | ||
pub ops: Box<[StringDiffOp]>, | ||
pub total_len: usize, | ||
} | ||
|
||
impl Diff { | ||
pub fn new(diffs: Vec<StringDiffOp>, total_len: usize) -> Self { | ||
Self { | ||
ops: diffs.into_boxed_slice(), | ||
total_len: total_len, | ||
} | ||
} | ||
|
||
pub fn distance(&self) -> usize { | ||
self.ops.len() | ||
} | ||
|
||
pub fn operations(&self) { | ||
for i in self.ops.iter() { | ||
println!("{:?}", i); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
pub struct DiffScoreConfig { | ||
pub sub_cost: f32, | ||
pub lowercase_sub_cost: f32, | ||
pub indel_cost: f32, | ||
pub transpose_cost: f32, | ||
// future properties here as needed | ||
} | ||
|
||
impl Default for DiffScoreConfig { | ||
fn default() -> Self { | ||
Self { | ||
sub_cost: 1.0, | ||
lowercase_sub_cost: 1.0, | ||
indel_cost: 1.0, | ||
transpose_cost: 1.0, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
#[test] | ||
fn test_default() { | ||
let test_struct = super::DiffScoreConfig::default(); | ||
assert_eq!(test_struct.sub_cost, 1.0); | ||
assert_eq!(test_struct.lowercase_sub_cost, 1.0); | ||
assert_eq!(test_struct.indel_cost, 1.0); | ||
assert_eq!(test_struct.transpose_cost, 1.0); | ||
|
||
let mut test_struct = super::DiffScoreConfig::default(); | ||
test_struct.sub_cost = 2.0; | ||
test_struct.lowercase_sub_cost = 2.0; | ||
test_struct.indel_cost = 2.0; | ||
test_struct.transpose_cost = 2.0; | ||
assert_eq!(test_struct.sub_cost, 2.0); | ||
assert_eq!(test_struct.lowercase_sub_cost, 2.0); | ||
assert_eq!(test_struct.indel_cost, 2.0); | ||
assert_eq!(test_struct.transpose_cost, 2.0); | ||
} | ||
} |
Oops, something went wrong.