Skip to content

Commit

Permalink
Formatted and added simple tests to temporal types
Browse files Browse the repository at this point in the history
  • Loading branch information
Davichet-e committed Oct 3, 2024
1 parent 867b4e0 commit 5f6fcda
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
**/target
MobilityDB
./MobilityDB
bitacora.md
Cargo.lock
.vscode
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ default = ["geos"]

[dev-dependencies]
csv = "1.3.0"
serial_test = "3.1.1"
2 changes: 1 addition & 1 deletion examples/01_hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use meos::{meos_initialize, TGeomPoint, MeosEnum};
use meos::{meos_initialize, MeosEnum, TGeomPoint};

fn main() {
meos_initialize("UTC");
Expand Down
20 changes: 13 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ pub mod errors;
pub use errors::ParseError;

pub mod temporal;
pub use temporal::{JSONCVariant, interpolation::TInterpolation, number::{tfloat::*, tint::*}, point::{tgeogpoint::*, tgeompoint::*, tpoint::TPointTrait}, temporal::Temporal};
pub use temporal::{
interpolation::TInterpolation,
number::{tfloat::*, tint::*},
point::{tgeogpoint::*, tgeompoint::*, tpoint::TPointTrait},
temporal::Temporal,
JSONCVariant,
};

pub(crate) mod utils;

Expand All @@ -42,17 +48,17 @@ unsafe extern "C" fn error_handler(_error_level: i32, _error_code: i32, message:
}

/// Initializes the underlying MEOS platform.
///
///
/// This function must be called before any other PyMEOS-related function is used.
///
///
/// # Arguments
///
/// * `tz` - A string slice (`&str`) indicating the desired timezone to be used.
///
///
/// * `tz` - A string slice (`&str`) indicating the desired timezone to be used.
///
/// ## Example
/// ```
/// # use meos::meos_initialize;
///
///
/// meos_initialize("UTC");
/// ```
pub fn meos_initialize(tz: &str) {
Expand Down
73 changes: 73 additions & 0 deletions src/temporal/number/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
pub mod tfloat;
pub mod tint;
pub mod tnumber;

#[cfg(test)]
mod tests {
use crate::meos_initialize;

use super::*;

#[test]
fn instant_tint() {
meos_initialize("UTC");
let string = "1@2018-01-01 08:00:00+00";
let result: tint::TInt = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Instant({})", string.to_owned())
);
}

#[test]
fn sequence_tint() {
meos_initialize("UTC");
let string = "[1@2018-01-01 08:00:00+00]";
let result: tint::TInt = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Sequence({})", string.to_owned())
);
}

#[test]
fn sequence_set_tint() {
meos_initialize("UTC");
let string = "{[1@2018-01-01 08:00:00+00]}";
let result: tint::TInt = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("SequenceSet({})", string.to_owned())
);
}

#[test]
fn instant_tfloat() {
meos_initialize("UTC");
let string = "1@2018-01-01 08:00:00+00";
let result: tfloat::TFloat = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Instant({})", string.to_owned())
);
}

#[test]
fn sequence_tfloat() {
meos_initialize("UTC");
let string = "[1@2018-01-01 08:00:00+00]";
let result: tfloat::TFloat = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Sequence({})", string.to_owned())
);
}

#[test]
fn sequence_set_tfloat() {
meos_initialize("UTC");
let string = "{[1@2018-01-01 08:00:00+00]}";
let result: tfloat::TFloat = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("SequenceSet({})", string.to_owned())
);
}
}
74 changes: 74 additions & 0 deletions src/temporal/point/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,77 @@
pub mod tgeogpoint;
pub mod tgeompoint;
pub mod tpoint;

#[cfg(test)]
#[serial_test::serial]
mod tests {
use crate::meos_initialize;

use super::*;

#[test]
fn instant_tgeompoint() {
meos_initialize("UTC");
let string = "POINT(0 0)@2018-01-01 08:00:00+00";
let result: tgeompoint::TGeomPoint = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Instant({})", string.to_owned())
);
}

#[test]
fn instant_tgeogpoint() {
meos_initialize("UTC");
let string = "POINT(0 0)@2018-01-01 08:00:00+00";
let result: tgeogpoint::TGeogPoint = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Instant({})", string.to_owned())
);
}

#[test]
fn sequence_tgeompoint() {
meos_initialize("UTC");
let string = "[POINT(0 0)@2018-01-01 08:00:00+00]";
let result: tgeompoint::TGeomPoint = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Sequence({})", string.to_owned())
);
}

#[test]
fn sequence_tgeogpoint() {
meos_initialize("UTC");
let string = "[POINT(0 0)@2018-01-01 08:00:00+00]";
let result: tgeogpoint::TGeogPoint = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Sequence({})", string.to_owned())
);
}

#[test]
fn sequence_set_tgeompoint() {
meos_initialize("UTC");
let string = "{[POINT(0 0)@2018-01-01 08:00:00+00]}";
let result: tgeompoint::TGeomPoint = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("SequenceSet({})", string.to_owned())
);
}

#[test]
fn sequence_set_tgeogpoint() {
meos_initialize("UTC");
let string = "{[POINT(0 0)@2018-01-01 08:00:00+00]}";
let result: tgeogpoint::TGeogPoint = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("SequenceSet({})", string.to_owned())
);
}
}
3 changes: 2 additions & 1 deletion src/temporal/point/tgeogpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use chrono::{DateTime, TimeZone};
use geos::Geometry;

use super::tpoint::{
create_set_of_geometries, geometry_to_gserialized, gserialized_to_geometry, impl_tpoint_traits, TPointTrait
create_set_of_geometries, geometry_to_gserialized, gserialized_to_geometry, impl_tpoint_traits,
TPointTrait,
};

pub struct TGeogPointInstant {
Expand Down
3 changes: 2 additions & 1 deletion src/temporal/point/tgeompoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use chrono::{DateTime, TimeZone};
use geos::Geometry;

use super::tpoint::{
create_set_of_geometries, geometry_to_gserialized, gserialized_to_geometry, impl_tpoint_traits, TPointTrait
create_set_of_geometries, geometry_to_gserialized, gserialized_to_geometry, impl_tpoint_traits,
TPointTrait,
};

pub struct TGeomPointInstant {
Expand Down
4 changes: 1 addition & 3 deletions src/temporal/point/tpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ pub(super) fn gserialized_to_geometry(

pub(super) fn create_set_of_geometries(values: &[Geometry]) -> *mut meos_sys::Set {
let cgeos: Vec<_> = values.iter().map(geometry_to_gserialized).collect();
unsafe {
meos_sys::geoset_make(cgeos.as_ptr() as *mut *const _, values.len() as i32)
}
unsafe { meos_sys::geoset_make(cgeos.as_ptr() as *mut *const _, values.len() as i32) }
}

impl fmt::Display for Point {
Expand Down
40 changes: 40 additions & 0 deletions src/temporal/tbool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,43 @@ impl BitOr<bool> for TBool {
}

impl TBoolTrait for TBool {}

#[cfg(test)]
mod tests {
use crate::meos_initialize;

use super::*;

#[test]
fn instant_tbool() {
meos_initialize("UTC");
let string = "t@2018-01-01 08:00:00+00";
let result: TBool = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Instant({})", string.to_owned())
);
}

#[test]
fn sequence_tbool() {
meos_initialize("UTC");
let string = "[t@2018-01-01 08:00:00+00]";
let result: TBool = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Sequence({})", string.to_owned())
);
}

#[test]
fn sequence_set_tbool() {
meos_initialize("UTC");
let string = "{[t@2018-01-01 08:00:00+00]}";
let result: TBool = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("SequenceSet({})", string.to_owned())
);
}
}
2 changes: 0 additions & 2 deletions src/temporal/tsequence_set.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


use super::{temporal::Temporal, tsequence::TSequence};

pub trait TSequenceSet: Temporal {
Expand Down
40 changes: 40 additions & 0 deletions src/temporal/ttext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,43 @@ impl Temporal for TText {
})
}
}

#[cfg(test)]
mod tests {
use crate::meos_initialize;

use super::*;

#[test]
fn instant_ttext() {
meos_initialize("UTC");
let string = "\"text\"@2018-01-01 08:00:00+00";
let result: TText = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Instant({})", string.to_owned())
);
}

#[test]
fn sequence_ttext() {
meos_initialize("UTC");
let string = "[\"text\"@2018-01-01 08:00:00+00]";
let result: TText = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("Sequence({})", string.to_owned())
);
}

#[test]
fn sequence_set_ttext() {
meos_initialize("UTC");
let string = "{[\"text\"@2018-01-01 08:00:00+00]}";
let result: TText = string.parse().unwrap();
assert_eq!(
format!("{result:?}"),
format!("SequenceSet({})", string.to_owned())
);
}
}

0 comments on commit 5f6fcda

Please sign in to comment.