mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[UnitTest] Add test for literal string serialization
This commit is contained in:
committed by
Ray Speth
parent
5f7a45e242
commit
d62eae26be
@@ -542,12 +542,11 @@ class TestSolutionSerialization(utilities.CanteraTest):
|
||||
# Check that items are ordered as expected
|
||||
self.assertEqual(
|
||||
list(data),
|
||||
['name', 'thermo', 'elements', 'species', 'state', 'custom-field']
|
||||
)
|
||||
self.assertEqual(
|
||||
list(data['custom-field']),
|
||||
['first', 'second', 'last']
|
||||
["name", "thermo", "elements", "species", "state",
|
||||
"custom-field", "literal-string"]
|
||||
)
|
||||
self.assertEqual(list(data["custom-field"]), ["first", "second", "last"])
|
||||
self.assertEqual(data["literal-string"], "spam\nand\neggs\n")
|
||||
|
||||
def test_input_data_debye_huckel(self):
|
||||
soln = ct.Solution('thermo-models.yaml', 'debye-huckel-B-dot-ak')
|
||||
|
||||
@@ -8,6 +8,10 @@ phases:
|
||||
first: true
|
||||
second: [3.0, 5.0]
|
||||
last: [100, 200, 300]
|
||||
literal-string: |
|
||||
spam
|
||||
and
|
||||
eggs
|
||||
species: [O2, NO, N2]
|
||||
state: {T: 500.0, P: 10 atm, X: {O2: 0.21, N2: 0.79}}
|
||||
|
||||
@@ -94,6 +98,9 @@ species:
|
||||
- [3.282537840E+00, 1.483087540E-03, -7.579666690E-07, 2.094705550E-10,
|
||||
-2.167177940E-14, -1.088457720E+03, 5.453231290E+00]
|
||||
note: "TPIS89"
|
||||
another-literal-string: |
|
||||
foo
|
||||
bar
|
||||
|
||||
- name: NO
|
||||
composition: {N: 1, O: 1}
|
||||
|
||||
@@ -58,6 +58,26 @@ TEST(YamlWriter, userDefinedFields)
|
||||
EXPECT_FALSE(spec2->transport->input.hasKey("bogus-field"));
|
||||
}
|
||||
|
||||
TEST(YamlWriter, literalStrings)
|
||||
{
|
||||
auto original = newSolution("ideal-gas.yaml", "simple");
|
||||
YamlWriter writer;
|
||||
writer.addPhase(original);
|
||||
writer.toYamlFile("generated-literal.yaml");
|
||||
auto duplicate = newSolution("generated-literal.yaml");
|
||||
auto thermo1 = original->thermo();
|
||||
auto thermo2 = duplicate->thermo();
|
||||
|
||||
EXPECT_EQ(thermo1->input()["literal-string"].asString(),
|
||||
thermo2->input()["literal-string"].asString());
|
||||
|
||||
auto spec1 = thermo1->species("O2");
|
||||
auto spec2 = thermo2->species("O2");
|
||||
|
||||
EXPECT_EQ(spec1->input["another-literal-string"].asString(),
|
||||
spec2->input["another-literal-string"].asString());
|
||||
}
|
||||
|
||||
TEST(YamlWriter, sharedSpecies)
|
||||
{
|
||||
auto original1 = newSolution("ideal-gas.yaml", "simple");
|
||||
|
||||
Reference in New Issue
Block a user