use bigsmiles::parse;
use pretty_assertions::assert_eq;
fn roundtrip(input: &str) -> String {
parse(input)
.unwrap_or_else(|e| panic!("parse({input:?}) failed: {e}"))
.to_string()
}
fn stable_roundtrip(input: &str) {
let first = roundtrip(input);
let second = roundtrip(&first);
assert_eq!(first, second, "display is not stable for {input:?}");
}
#[test]
fn display_polyethylene_no_bond() {
assert_eq!(roundtrip("{[]CC[]}"), "{[]CC[]}");
stable_roundtrip("{[]CC[]}");
}
#[test]
fn display_polypropylene_no_bond() {
assert_eq!(roundtrip("{[]CC(C)[]}"), "{[]CC(C)[]}");
stable_roundtrip("{[]CC(C)[]}");
}
#[test]
fn display_polyethylene_non_directional() {
assert_eq!(roundtrip("{[$]CC[$]}"), "{[$]CC[$]}");
stable_roundtrip("{[$]CC[$]}");
}
#[test]
fn display_indexed_non_directional() {
assert_eq!(roundtrip("{[$1]CC[$1]}"), "{[$1]CC[$1]}");
stable_roundtrip("{[$1]CC[$1]}");
}
#[test]
fn display_indexed_directional() {
assert_eq!(roundtrip("{[<2]CC[>2]}"), "{[<2]CC[>2]}");
stable_roundtrip("{[<2]CC[>2]}");
}
#[test]
fn display_isotactic_polypropylene() {
assert_eq!(roundtrip("{[>][<]CC(C)[>][<]}"), "{[>][<]CC(C)[>][<]}");
stable_roundtrip("{[>][<]CC(C)[>][<]}");
}
#[test]
fn display_ethylene_propylene_copolymer() {
assert_eq!(
roundtrip("{[$]CC[$],[$]CC(C)[$]}"),
"{[$]CC[$],[$]CC(C)[$]}"
);
stable_roundtrip("{[$]CC[$],[$]CC(C)[$]}");
}
#[test]
fn display_three_unit_copolymer() {
assert_eq!(
roundtrip("{[$]CC[$],[$]CCC[$],[$]CCCC[$]}"),
"{[$]CC[$],[$]CCC[$],[$]CCCC[$]}"
);
stable_roundtrip("{[$]CC[$],[$]CCC[$],[$]CCCC[$]}");
}
#[test]
fn display_with_end_group() {
assert_eq!(roundtrip("{[$]CC[$];[$]CCO[$]}"), "{[$]CC[$];[$]CCO[$]}");
stable_roundtrip("{[$]CC[$];[$]CCO[$]}");
}
#[test]
fn display_alpha_omega_dimethyl_polyethylene() {
assert_eq!(roundtrip("CC{[$]CC[$]}CC"), "CC{[$]CC[$]}CC");
stable_roundtrip("CC{[$]CC[$]}CC");
}
#[test]
fn display_plain_smiles() {
assert_eq!(roundtrip("CCO"), "OCC");
stable_roundtrip("CCO");
}
#[test]
fn display_polystyrene() {
assert_eq!(roundtrip("{[]CC(c1ccccc1)[]}"), "{[]CC(c1ccccc1)[]}");
stable_roundtrip("{[]CC(c1ccccc1)[]}");
}
#[test]
fn display_double_bond_repeat_unit() {
assert_eq!(roundtrip("{[$]C=C[$]}"), "{[$]C=C[$]}");
stable_roundtrip("{[$]C=C[$]}");
}