Skip to content

Commit 00e2b0a

Browse files
authored
Merge pull request #19 from segeljakt/rust-dev
Refactor and add tests
2 parents 4cdb1ed + 40e60b2 commit 00e2b0a

File tree

11 files changed

+302
-140
lines changed

11 files changed

+302
-140
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# will have compiled files and executables
33
debug/
44
target/
5+
wip/
56

67
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
78
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

.travis.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
dist: bionic
2-
language: cpp
3-
jobs:
2+
matrix:
43
include:
5-
- script: cpp/build-and-test.sh
4+
- language: cpp
5+
rust: stable
6+
jobs:
7+
allow_failures:
8+
- rust: nightly
9+
fast_finish: true
10+
- language: cpp
11+
script: cpp/build-and-test.sh

rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rand = "0.7.3"
2525

2626
[dev-dependencies]
2727
criterion = "0.3.3"
28+
trybuild = "1.0.30"
2829

2930
[profile.dev]
3031
opt-level = 0

rust/src/reactive/flat_fat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alga::general::AbstractMonoid;
22
use alga::general::Operator;
33
use std::collections::HashSet;
44

5-
pub trait FAT<Value, BinOp>
5+
pub(crate) trait FAT<Value, BinOp>
66
where
77
Value: AbstractMonoid<BinOp> + Clone,
88
BinOp: Operator,
@@ -33,7 +33,7 @@ where
3333
fn suffix(&self, i: usize) -> Value;
3434
}
3535

36-
pub struct FlatFAT<Value, BinOp>
36+
pub(crate) struct FlatFAT<Value, BinOp>
3737
where
3838
Value: AbstractMonoid<BinOp> + Clone,
3939
BinOp: Operator,

rust/tests/common.rs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
use alga::general::AbstractGroup;
2+
use alga::general::AbstractLoop;
3+
use alga::general::AbstractMagma;
4+
use alga::general::AbstractMonoid;
5+
use alga::general::AbstractQuasigroup;
6+
use alga::general::AbstractSemigroup;
7+
use alga::general::Identity;
8+
use alga::general::Operator;
9+
use alga::general::TwoSidedInverse;
10+
11+
/// Abstract Algebra Lattice:
12+
/// Borrowed from https://docs.rs/alga/0.9.3/alga/general/index.html
13+
///
14+
/// AbstractMagma
15+
/// |
16+
/// _______/ \______
17+
/// / \
18+
/// divisibility associativity
19+
/// | |
20+
/// V V
21+
/// AbstractQuasigroup AbstractSemigroup
22+
/// | |
23+
/// identity identity
24+
/// | |
25+
/// V V
26+
/// AbstractLoop AbstractMonoid
27+
/// | |
28+
/// associativity invertibility
29+
/// \______ _______/
30+
/// \ /
31+
/// |
32+
/// V
33+
/// AbstractGroup
34+
/// |
35+
/// commutativity
36+
/// |
37+
/// V
38+
/// AbstractGroupAbelian
39+
40+
/// An integer value
41+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
42+
pub struct Int(pub i32);
43+
44+
/// Binary operator for calculating the arithmetic sum.
45+
/// Has the following properties:
46+
/// * Invertibility
47+
/// * Associativity
48+
/// * Commutativity
49+
#[derive(Copy, Clone)]
50+
pub struct Sum;
51+
52+
impl Operator for Sum {
53+
fn operator_token() -> Sum {
54+
Sum
55+
}
56+
}
57+
58+
impl Identity<Sum> for Int {
59+
fn identity() -> Int {
60+
Int(0)
61+
}
62+
}
63+
64+
impl AbstractMagma<Sum> for Int {
65+
fn operate(&self, other: &Self) -> Self {
66+
Int(self.0 + other.0)
67+
}
68+
}
69+
70+
impl TwoSidedInverse<Sum> for Int {
71+
fn two_sided_inverse(&self) -> Int {
72+
Int(-self.0)
73+
}
74+
}
75+
76+
impl AbstractSemigroup<Sum> for Int {}
77+
impl AbstractMonoid<Sum> for Int {}
78+
impl AbstractQuasigroup<Sum> for Int {}
79+
impl AbstractLoop<Sum> for Int {}
80+
impl AbstractGroup<Sum> for Int {}
81+
82+
/// Binary operator for calculating the maximum Int.
83+
/// Has the following properties:
84+
/// * Associativity
85+
/// * Commutativity
86+
#[derive(Copy, Clone)]
87+
pub(crate) struct Max;
88+
89+
impl Operator for Max {
90+
fn operator_token() -> Max {
91+
Max
92+
}
93+
}
94+
95+
impl Identity<Max> for Int {
96+
fn identity() -> Int {
97+
Int(std::i32::MIN)
98+
}
99+
}
100+
101+
impl AbstractMagma<Max> for Int {
102+
fn operate(&self, other: &Self) -> Self {
103+
if self.0 > other.0 {
104+
*self
105+
} else {
106+
*other
107+
}
108+
}
109+
}
110+
111+
impl AbstractSemigroup<Max> for Int {}
112+
impl AbstractMonoid<Max> for Int {}

rust/tests/fifo-window.rs

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)