-
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.
- Loading branch information
0 parents
commit e1343ec
Showing
5 changed files
with
161 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock |
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,59 @@ | ||
language: rust | ||
cache: | ||
directories: | ||
- /home/travis/.cargo | ||
sudo: false | ||
|
||
rust: | ||
- 1.31.0 # Oldest supported | ||
- stable | ||
- beta | ||
- nightly | ||
os: | ||
- linux | ||
- osx | ||
- windows | ||
|
||
# Cribbed from UOM .travis.yml | ||
matrix: | ||
allow_failures: | ||
- rust: nightly | ||
include: | ||
- name: "Rust: 1.31.0" | ||
rust: 1.31.0 | ||
script: | | ||
cargo build --verbose | ||
- name: "Rust: stable + tests" | ||
rust: stable | ||
script: | | ||
cargo test --all --verbose | ||
- name: Rustfmt | ||
rust: 1.33.0 | ||
install: | ||
- rustup component add rustfmt | ||
script: | ||
- cargo fmt -- --check | ||
- name: Clippy | ||
rust: 1.33.0 | ||
install: | ||
- rustup component add clippy | ||
script: | ||
- RUSTFLAGS="-D warnings" cargo clippy --tests -- -D clippy::all | ||
- name: Tarpaulin | ||
rust: 1.33.0 | ||
sudo: required | ||
script: | ||
- docker run --security-opt seccomp=unconfined -v "$PWD:/volume" xd009642/tarpaulin sh -c "cargo build && cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID" | ||
|
||
install: | ||
- rustc -Vv | ||
- cargo -V | ||
|
||
script: | | ||
set -e | ||
cargo test --verbose | ||
before_cache: | ||
- rm -rf /home/travis/.cargo/registry | ||
|
||
notifications: | ||
email: |
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,11 @@ | ||
[package] | ||
name = "piecewise" | ||
version = "0.1.0" | ||
authors = ["Scott Moeller <electronjoe@gmail.com>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
intervals-general = "0.1.0" | ||
|
||
[patch.crates-io] | ||
intervals-general = {path = "../intervals-general" } |
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,2 @@ | ||
format_doc_comments = true | ||
wrap_comments = true |
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,86 @@ | ||
use intervals_general::interval::Interval; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
pub struct ValueOverInterval<T, U> { | ||
pub(crate) interval: Interval<T>, | ||
pub(crate) value: U, | ||
} | ||
|
||
impl<T, U> ValueOverInterval<T, U> { | ||
/// Create a new ValueOverInterval | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use intervals_general::interval::Interval; | ||
/// use piecewise::ValueOverInterval; | ||
/// | ||
/// let value_over_interval = ValueOverInterval::new(Interval::Unbounded::<u32> {}, 5.0); | ||
/// ``` | ||
pub fn new(interval: Interval<T>, value: U) -> ValueOverInterval<T, U> { | ||
ValueOverInterval { interval, value } | ||
} | ||
|
||
/// Fetch an immutable reference to the Interval | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use intervals_general::bound_pair::BoundPair; | ||
/// use intervals_general::interval::Interval; | ||
/// use piecewise::ValueOverInterval; | ||
/// # fn main() -> std::result::Result<(), String> { | ||
/// let bounds = BoundPair::new(1.0, 2.0).ok_or("invalid BoundPair")?; | ||
/// let value_over_interval = ValueOverInterval::new(Interval::Closed { bound_pair: bounds }, 4); | ||
/// assert_eq!(*value_over_interval.value(), 4); | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub fn interval(&self) -> &Interval<T> { | ||
&self.interval | ||
} | ||
|
||
/// Fetch an immutable reference to the value | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use intervals_general::bound_pair::BoundPair; | ||
/// use intervals_general::interval::Interval; | ||
/// use piecewise::ValueOverInterval; | ||
/// # fn main() -> std::result::Result<(), String> { | ||
/// let bounds = BoundPair::new(1.0, 2.0).ok_or("invalid BoundPair")?; | ||
/// let value_over_interval = ValueOverInterval::new(Interval::Closed { bound_pair: bounds }, 4); | ||
/// assert_eq!( | ||
/// *value_over_interval.interval(), | ||
/// Interval::Closed { bound_pair: bounds } | ||
/// ); | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub fn value(&self) -> &U { | ||
&self.value | ||
} | ||
} | ||
|
||
impl<T, U, V> std::ops::Mul<V> for ValueOverInterval<T, U> | ||
where | ||
U: std::ops::Mul<V, Output = U>, | ||
{ | ||
type Output = ValueOverInterval<T, U>; | ||
|
||
fn mul(self, rhs: V) -> Self::Output { | ||
ValueOverInterval { | ||
interval: self.interval, | ||
value: self.value * rhs, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
} |