Skip to content

Commit 0c89d07

Browse files
committed
#2538 improved search_tag and tests
1 parent c177fda commit 0c89d07

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

pybamm/experiments/experiment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,5 +464,6 @@ def search_tag(self, tag):
464464
tags = tag_str[0:-1].split(",")
465465
if tag in tags:
466466
cycles.append(i)
467+
break
467468

468469
return cycles

tests/unit/test_experiments/test_experiment.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -477,22 +477,29 @@ def test_termination(self):
477477
def test_search_tag(self):
478478
experiment = pybamm.Experiment(
479479
[
480-
"Discharge at 1C for 0.5 hours [tag1]",
480+
(
481+
"Discharge at 1C for 0.5 hours [tag1]",
482+
),
481483
"Discharge at C/20 for 0.5 hours [tag2,tag3]",
482-
"Charge at 0.5 C for 45 minutes",
483-
"Discharge at 1 A for 0.5 hours",
484-
"Charge at 200 mA for 45 minutes (1 minute period)",
485-
"Discharge at 1W for 0.5 hours",
486-
"Charge at 200mW for 45 minutes",
487-
"Rest for 10 minutes (5 minute period) [tag1,tag3]",
488-
],
489-
period="20 seconds",
484+
(
485+
"Charge at 0.5 C for 45 minutes [tag2]",
486+
"Discharge at 1 A for 0.5 hours [tag3]",
487+
),
488+
"Charge at 200 mA for 45 minutes (1 minute period) [tag5]",
489+
(
490+
"Discharge at 1W for 0.5 hours [tag4]",
491+
"Charge at 200mW for 45 minutes [tag4]",
492+
),
493+
"Rest for 10 minutes (5 minute period) [tag1,tag3,tag4]",
494+
]
490495
)
491496

492-
self.assertEqual(experiment.search_tag("tag1"), [0, 7])
493-
self.assertEqual(experiment.search_tag("tag2"), [1])
494-
self.assertEqual(experiment.search_tag("tag3"), [1, 7])
495-
self.assertEqual(experiment.search_tag("tag4"), [])
497+
self.assertEqual(experiment.search_tag("tag1"), [0, 5])
498+
self.assertEqual(experiment.search_tag("tag2"), [1, 2])
499+
self.assertEqual(experiment.search_tag("tag3"), [1, 2, 5])
500+
self.assertEqual(experiment.search_tag("tag4"), [4, 5])
501+
self.assertEqual(experiment.search_tag("tag5"), [3])
502+
self.assertEqual(experiment.search_tag("no_tag"), [])
496503

497504

498505
if __name__ == "__main__":

0 commit comments

Comments
 (0)