// 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 clapme; use clapme::ClapMe; /// The parameters needed to configure a square well system. #[derive(PartialEq, Debug, ClapMe)] struct Vector3d { x: T, y: T, z: T, } /// A description of the cell dimensions #[derive(PartialEq, Debug, ClapMe)] #[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, ClapMe)] struct SquareWellParams { well_width: f64, _dim: CellDimensions, } #[allow(non_snake_case)] #[derive(PartialEq, Debug, ClapMe)] struct SadParams { /// The minimum temperature we are interested in. min_T: f64, /// The seed for the random number generator. seed: Option, } #[derive(PartialEq, Debug, ClapMe)] enum Params { ResumeFrom(String), _Params { _sys: SP, _mc: MP, }, } #[derive(PartialEq, Debug, ClapMe)] struct Simple { simple: u64, } #[derive(PartialEq, Debug, ClapMe)] struct Naive { naive: String, } #[test] fn craziness() { type P = Params; println!("help: {}", P::help_message("foo")); println!("\n\n\n\n"); assert!(P::help_message("foo").contains("--resume-from ")); assert!(P::help_message("foo").contains("--well-width ")); assert!(P::help_message("foo").contains("--cell-volume ")); assert!(P::help_message("foo").contains("--cell-width-x ")); assert!(!P::help_message("foo").contains("--dim- ")); assert_eq!(Params::ResumeFrom::("hello".to_string()), P::from_iter(&["", "--resume-from", "hello"]).unwrap()); assert_eq!(Params::ResumeFrom::("hello".to_string()), Params::::from_iter(&["", "--resume-from", "hello"]).unwrap()); assert_eq!(Params::_Params:: { _sys: Simple { simple: 37, }, _mc: Naive { naive: "goodbye".to_string(), }, }, Params::::from_iter(&["", "--simple", "37", "--naive", "goodbye"]).unwrap()); assert_eq!(Params::_Params:: { _sys: Simple { simple: 137, }, _mc: SadParams { min_T: 0.2, seed: None, }, }, Params::::from_iter(&["", "--simple", "137", "--min-T", "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::from_iter(&["", "--well-width", "1.3", "--cell-volume", "5", "--min-T", "0.2"]).unwrap()); }