From f1f43abea88ca08d7b10f42671e18aeba4a8b606 Mon Sep 17 00:00:00 2001 From: Myeongseon Choi Date: Tue, 12 Nov 2024 22:45:19 +0900 Subject: [PATCH 1/2] make test work --- src/lib.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 31c705a..4e04192 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ pub mod system{ pub struct System{} impl System{ - pub fn add_particle(&mut self, mass: f32){ + pub fn add_particle(&mut self, _mass: f32){ // Todo: Rust-OpenMM unimplemented!() } @@ -17,37 +17,37 @@ pub mod system{ unimplemented!() } - pub fn get_particle_mass(&self, index: usize) -> f32{ + pub fn get_particle_mass(&self, _index: usize) -> f32{ // Todo: Rust-OpenMM unimplemented!() } - pub fn set_particle_mass(&mut self, index: usize, mass: f32){ + pub fn set_particle_mass(&mut self, _index: usize, _mass: f32){ // Todo: Rust-OpenMM unimplemented!() } - pub fn is_virtual_site(&self, index: usize) -> bool{ + pub fn is_virtual_site(&self, _index: usize) -> bool{ // Todo: Rust-OpenMM unimplemented!() } - pub fn get_virtual_site(&self, index: usize) -> Option>{ + pub fn get_virtual_site(&self, _index: usize) -> Option>{ // Todo: Rust-OpenMM unimplemented!() } - pub fn set_virtual_site(&mut self, index: usize, vsite: Option>){ + pub fn set_virtual_site(&mut self, _index: usize, _vsite: Option>){ // Todo: Rust-OpenMM unimplemented!() } - pub fn add_constraint(&mut self, p1: usize, p2: usize, dist: f32){ + pub fn add_constraint(&mut self, _p1: usize, _p2: usize, _dist: f32){ // Todo: Rust-OpenMM unimplemented!() } - pub fn remove_constraint(&mut self, index: usize){ + pub fn remove_constraint(&mut self, _index: usize){ // Todo: Rust-OpenMM unimplemented!() } @@ -57,22 +57,22 @@ pub mod system{ unimplemented!() } - pub fn get_constraint_parameters(&self, index: usize) -> (usize, usize, f32){ + pub fn get_constraint_parameters(&self, _index: usize) -> (usize, usize, f32){ // Todo: Rust-OpenMM unimplemented!() } - pub fn set_constraint_parameters(&mut self, index: usize, p1: usize, p2: usize, dist: f32){ + pub fn set_constraint_parameters(&mut self, _index: usize, _p1: usize, _p2: usize, _dist: f32){ // Todo: Rust-OpenMM unimplemented!() } - pub fn add_force(&mut self, force: Box){ + pub fn add_force(&mut self, _force: Box){ // Todo: Rust-OpenMM unimplemented!() } - pub fn remove_force(&mut self, index: usize){ + pub fn remove_force(&mut self, _index: usize){ // Todo: Rust-OpenMM unimplemented!() } @@ -82,7 +82,7 @@ pub mod system{ unimplemented!() } - pub fn get_force(&self, index: usize) -> Box{ + pub fn get_force(&self, _index: usize) -> Box{ // Todo: Rust-OpenMM unimplemented!() } @@ -116,7 +116,7 @@ pub mod virtual_site{ pub weight2: f32, } impl TwoParticleAverageSite{ - pub fn new(p1: usize, p2: usize, weight1: f32, weight2: f32) -> Self{ + pub fn new(_p1: usize, _p2: usize, _weight1: f32, _weight2: f32) -> Self{ unimplemented!() } } -- 2.49.1 From b88213f20098727fcb5357ab68db5ce9fd082922 Mon Sep 17 00:00:00 2001 From: Myeongseon Choi Date: Wed, 13 Nov 2024 00:17:19 +0900 Subject: [PATCH 2/2] format --- src/lib.rs | 141 +++++++++++++++++++++++++++-------------------------- 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4e04192..61b0bcf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,149 +1,151 @@ - - - -pub mod system{ +pub mod system { use crate::force::Force; use crate::virtual_site::VirtualSite; - pub struct System{} - impl System{ - pub fn add_particle(&mut self, _mass: f32){ + pub struct System {} + impl System { + pub fn add_particle(&mut self, _mass: f32) { // Todo: Rust-OpenMM unimplemented!() } - pub fn get_num_particles(&self) -> usize{ - // Todo: Rust-OpenMM - unimplemented!() - } - - pub fn get_particle_mass(&self, _index: usize) -> f32{ + pub fn get_num_particles(&self) -> usize { // Todo: Rust-OpenMM unimplemented!() } - pub fn set_particle_mass(&mut self, _index: usize, _mass: f32){ - // Todo: Rust-OpenMM - unimplemented!() - } - - pub fn is_virtual_site(&self, _index: usize) -> bool{ + pub fn get_particle_mass(&self, _index: usize) -> f32 { // Todo: Rust-OpenMM unimplemented!() } - pub fn get_virtual_site(&self, _index: usize) -> Option>{ + pub fn set_particle_mass(&mut self, _index: usize, _mass: f32) { // Todo: Rust-OpenMM unimplemented!() } - pub fn set_virtual_site(&mut self, _index: usize, _vsite: Option>){ + pub fn is_virtual_site(&self, _index: usize) -> bool { // Todo: Rust-OpenMM unimplemented!() } - pub fn add_constraint(&mut self, _p1: usize, _p2: usize, _dist: f32){ + pub fn get_virtual_site(&self, _index: usize) -> Option> { // Todo: Rust-OpenMM unimplemented!() } - pub fn remove_constraint(&mut self, _index: usize){ + pub fn set_virtual_site(&mut self, _index: usize, _vsite: Option>) { // Todo: Rust-OpenMM unimplemented!() } - pub fn get_num_constraints(&self) -> usize{ + pub fn add_constraint(&mut self, _p1: usize, _p2: usize, _dist: f32) { // Todo: Rust-OpenMM unimplemented!() - } + } - pub fn get_constraint_parameters(&self, _index: usize) -> (usize, usize, f32){ + pub fn remove_constraint(&mut self, _index: usize) { // Todo: Rust-OpenMM unimplemented!() - } + } - pub fn set_constraint_parameters(&mut self, _index: usize, _p1: usize, _p2: usize, _dist: f32){ + pub fn get_num_constraints(&self) -> usize { // Todo: Rust-OpenMM unimplemented!() - } + } - pub fn add_force(&mut self, _force: Box){ + pub fn get_constraint_parameters(&self, _index: usize) -> (usize, usize, f32) { // Todo: Rust-OpenMM unimplemented!() - } + } - pub fn remove_force(&mut self, _index: usize){ + pub fn set_constraint_parameters( + &mut self, + _index: usize, + _p1: usize, + _p2: usize, + _dist: f32, + ) { // Todo: Rust-OpenMM unimplemented!() - } + } - pub fn get_num_forces(&self) -> usize{ + pub fn add_force(&mut self, _force: Box) { // Todo: Rust-OpenMM unimplemented!() - } + } - pub fn get_force(&self, _index: usize) -> Box{ + pub fn remove_force(&mut self, _index: usize) { // Todo: Rust-OpenMM unimplemented!() - } + } + + pub fn get_num_forces(&self) -> usize { + // Todo: Rust-OpenMM + unimplemented!() + } + + pub fn get_force(&self, _index: usize) -> Box { + // Todo: Rust-OpenMM + unimplemented!() + } } } -pub mod force{ +pub mod force { use std::fmt::Debug; - pub trait Force : Debug{} + pub trait Force: Debug {} #[derive(Debug, Clone, PartialEq)] - pub struct HarmonicAngleForce{} - impl Force for HarmonicAngleForce{} + pub struct HarmonicAngleForce {} + impl Force for HarmonicAngleForce {} #[derive(Debug, Clone, PartialEq)] - pub struct HarmonicBondForce{} - impl Force for HarmonicBondForce{} + pub struct HarmonicBondForce {} + impl Force for HarmonicBondForce {} } -pub mod virtual_site{ +pub mod virtual_site { use std::fmt::Debug; - pub trait VirtualSite : Debug{} + pub trait VirtualSite: Debug {} #[derive(Debug, Clone, PartialEq)] - pub struct TwoParticleAverageSite{ + pub struct TwoParticleAverageSite { pub p1: usize, pub p2: usize, pub weight1: f32, pub weight2: f32, } - impl TwoParticleAverageSite{ - pub fn new(_p1: usize, _p2: usize, _weight1: f32, _weight2: f32) -> Self{ + impl TwoParticleAverageSite { + pub fn new(_p1: usize, _p2: usize, _weight1: f32, _weight2: f32) -> Self { unimplemented!() } } - impl VirtualSite for TwoParticleAverageSite{} + impl VirtualSite for TwoParticleAverageSite {} } - #[cfg(test)] -mod test{ - use crate::system::System; +mod test { use crate::force::{HarmonicAngleForce, HarmonicBondForce}; + use crate::system::System; use crate::virtual_site::TwoParticleAverageSite; // Todo: Rust-OpenMM #[ignore] #[test] - fn test_system_particles(){ + fn test_system_particles() { let num_particles = 10; - let mut system = System{}; + let mut system = System {}; - for i in 0..num_particles{ + for i in 0..num_particles { system.add_particle(1.0 + 0.1 * i as f32); } system.set_particle_mass(5, 100.0); assert_eq!(system.get_num_particles(), num_particles); - for i in 0..num_particles{ + for i in 0..num_particles { let expected_mass = if i == 5 { 100.0 } else { 1.0 + 0.1 * i as f32 }; assert_eq!(system.get_particle_mass(i), expected_mass); } @@ -152,18 +154,18 @@ mod test{ // Todo: Rust-OpenMM #[ignore] #[test] - fn test_system_constraints(){ + fn test_system_constraints() { let num_particles = 10; - let mut system = System{}; + let mut system = System {}; - for i in 0..num_particles - 1{ + for i in 0..num_particles - 1 { system.add_constraint(i, i + 1, 0.2 * i as f32); } system.remove_constraint(5); system.set_constraint_parameters(3, 0, 5, 99.0); assert_eq!(system.get_num_constraints(), num_particles - 2); - for i in 0..num_particles - 2{ + for i in 0..num_particles - 2 { let (p1, p2, dist) = system.get_constraint_parameters(i); if i == 3 { assert_eq!(p1, 0); @@ -181,12 +183,12 @@ mod test{ // Todo: Rust-OpenMM #[ignore] #[test] - fn test_system_force(){ - let mut system = System{}; - let bonds = HarmonicBondForce{}; + fn test_system_force() { + let mut system = System {}; + let bonds = HarmonicBondForce {}; system.add_force(Box::new(bonds)); - let angles = HarmonicAngleForce{}; + let angles = HarmonicAngleForce {}; system.add_force(Box::new(angles)); assert_eq!(system.get_num_forces(), 2); @@ -203,25 +205,24 @@ mod test{ // Todo: Rust-OpenMM #[ignore] #[test] - fn test_system_virtual_site(){ - let mut system = System{}; + fn test_system_virtual_site() { + let mut system = System {}; let num_particles = 10; - for i in 0..num_particles{ + for i in 0..num_particles { system.add_particle(1.0); assert!(!system.is_virtual_site(i)); } let vsite = TwoParticleAverageSite::new(2, 3, 0.4, 0.6); system.set_virtual_site(4, Some(Box::new(vsite))); - for i in 0..num_particles{ + for i in 0..num_particles { assert_eq!(system.is_virtual_site(i), i == 4); } // Todo: Rust-OpenMM // assert_eq!(system.get_virtual_site(4), Some(Box::new(vsite))); system.set_virtual_site(4, None); - for i in 0..num_particles{ + for i in 0..num_particles { assert!(!system.is_virtual_site(i)); } } } - -- 2.49.1