// Copyright 2018 David Roundy // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. #[macro_use] extern crate auto_args; use auto_args::AutoArgs; use std::ffi::OsString; /// The parameters needed to configure a square well system. #[derive(PartialEq, Debug, AutoArgs)] struct Vector3d { x: T, y: T, z: T, } /// A description of the cell dimensions #[derive(PartialEq, Debug, AutoArgs)] #[allow(non_snake_case)] enum CellDimensions { /// The three widths of the cell CellWidth(Vector3d), /// The volume of the cell CellVolume(f64), } /// The parameters needed to configure a square well system. #[derive(PartialEq, Debug, AutoArgs)] struct SquareWellParams { well_width: f64, _dim: CellDimensions, } #[allow(non_snake_case)] #[derive(PartialEq, Debug, AutoArgs)] struct SadParams { /// The minimum temperature we are interested in. min_T: f64, /// The seed for the random number generator. seed: Option, } #[derive(PartialEq, Debug, AutoArgs)] enum Params { ResumeFrom(String), _Params { _sys: SP, _mc: MP }, } #[derive(PartialEq, Debug, AutoArgs)] struct Simple { simple: u64, } #[derive(PartialEq, Debug, AutoArgs)] struct Naive { naive: String, } #[test] fn craziness() { type P = Params; println!("help: {}", P::help()); println!("\n\n\n\n"); assert!(P::help().contains("--resume-from ")); assert!(P::help().contains("--well-width ")); assert!(P::help().contains("--cell-volume ")); assert!(P::help().contains("--cell-width-x ")); assert!(!P::help().contains("--dim- ")); assert_eq!( Params::ResumeFrom::("hello".to_string()), P::parse_vec(vec![ OsString::from("--resume-from"), OsString::from("hello") ]) .unwrap() ); assert_eq!( Params::ResumeFrom::("hello".to_string()), Params::::parse_vec(vec![ OsString::from("--resume-from"), OsString::from("hello") ]) .unwrap() ); assert_eq!( Params::_Params:: { _sys: Simple { simple: 37 }, _mc: Naive { naive: "goodbye".to_string(), }, }, Params::::parse_vec(vec![ OsString::from("--simple"), OsString::from("37"), OsString::from("--naive"), OsString::from("goodbye") ]) .unwrap() ); assert_eq!( Params::_Params:: { _sys: Simple { simple: 137 }, _mc: SadParams { min_T: 0.2, seed: None, }, }, Params::::parse_vec(vec![ OsString::from("--simple"), OsString::from("137"), OsString::from("--min-T"), OsString::from("0.2") ]) .unwrap() ); assert_eq!( Params::_Params:: { _sys: SquareWellParams { well_width: 1.3, _dim: CellDimensions::CellVolume(5.0), }, _mc: SadParams { min_T: 0.2, seed: None, }, }, P::parse_vec(vec![ OsString::from("--well-width"), OsString::from("1.3"), OsString::from("--cell-volume"), OsString::from("5"), OsString::from("--min-T"), OsString::from("0.2") ]) .unwrap() ); }