Skip to content

Commit

Permalink
#308 Replace deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizu committed Oct 29, 2018
1 parent 65da4a1 commit 1756134
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 36 deletions.
6 changes: 6 additions & 0 deletions ecell4/core/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ class rule_based_expression_matcher<std::vector<Species> >
* New interfaces for the rule-based modeling
*/

inline Integer count_species_matches(const Species& pttrn, const Species& sp)
{
return static_cast<Integer>(
context::rule_based_expression_matcher<Species>(pttrn).count(sp));
}

inline Species format_species(const Species& sp)
{
return context::format_species(sp);
Expand Down
2 changes: 1 addition & 1 deletion ecell4/core/Species.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool Species::operator>(const Species& rhs) const
Integer Species::count(const Species& sp) const
{
// return count_spmatches(*this, sp);
throw NotSupported("deprecated");
throw NotSupported("Function 'Species::count' is deprecated. Rather use 'count_species_matches'");
}

void Species::add_unit(const UnitSpecies& usp)
Expand Down
44 changes: 20 additions & 24 deletions python/lib/ecell4/Species.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -334,30 +334,26 @@ cdef Species Species_from_Cpp_Species(Cpp_Species *sp):
#
# """
# return context.spmatch(deref(pttrn.thisptr), deref(sp.thisptr))
#
# def count_spmatches(Species pttrn, Species sp):
# """count_spmatches(pttrn, sp) -> Integer
#
# Count the number of matches for a pattern given as a ``Species``.
#
# Parameters
# ----------
# pttrn : Species
# A pattern.
# sp : Species
# A target.
#
# Returns
# -------
# Integer:
# The number of matches.
#
# Notes
# -----
# Rather use ``Species.count``.
#
# """
# return context.count_spmatches(deref(pttrn.thisptr), deref(sp.thisptr))

def count_species_matches(Species pttrn, Species sp):
"""count_species_matches(pttrn, sp) -> Integer
Count the number of matches for a pattern given as a ``Species``.
Parameters
----------
pttrn : Species
A pattern.
sp : Species
A target.
Returns
-------
Integer:
The number of matches.
"""
return context.count_species_matches(deref(pttrn.thisptr), deref(sp.thisptr))

def format_species(Species sp):
"""format_species(sp) -> Species
Expand Down
1 change: 1 addition & 0 deletions python/lib/ecell4/context.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ from core cimport Cpp_Species, Cpp_ReactionRule

cdef extern from "ecell4/core/Context.hpp" namespace "ecell4":
Cpp_Species format_species(Cpp_Species&)
Integer count_species_matches(Cpp_Species, Cpp_Species)
# string unique_serial(Cpp_Species&)

# bool spmatch(Cpp_Species, Cpp_Species)
Expand Down
10 changes: 5 additions & 5 deletions python/tests/core/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ def setUp(self):

def test1(self):
sp1 = Species("A")
self.assertEqual(sp1.count(Species("A")), 1)
self.assertEqual(sp1.count(Species("A.A")), 2)
self.assertEqual(count_species_matches(sp1, Species("A")), 1)
self.assertEqual(count_species_matches(sp1, Species("A.A")), 2)

def test2(self):
sp1 = Species("A.B")
self.assertEqual(sp1.count(Species("A.B")), 1)
self.assertEqual(sp1.count(Species("B.A")), 1)
self.assertEqual(count_species_matches(sp1, Species("A.B")), 1)
self.assertEqual(count_species_matches(sp1, Species("B.A")), 1)

def test3(self):
sp1 = Species("A(p=u^_)")
self.assertEqual(sp1.count(Species("A(p=u^1).B(b^1)")), 1)
self.assertEqual(count_species_matches(sp1, Species("A(p=u^1).B(b^1)")), 1)


if __name__ == "__main__":
Expand Down
11 changes: 5 additions & 6 deletions python/tests/core/test_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test2(self):
sp.add_unit(UnitSpecies('C'))
sp.add_unit(UnitSpecies('A'))
self.assertEqual(sp.serial(), 'B.C.A')
self.assertEqual(sp.num_units(), 3)
self.assertEqual(len(sp.units()), 3)

def test3(self):
sp = Species('A')
Expand Down Expand Up @@ -47,14 +47,13 @@ def test3(self):
or (key == 'hoge' and value == 'hage'))

def test4(self):
sp = Species()
sp.deserialize('A.B.C')
sp = Species('A.B.C')
self.assertEqual(sp.serial(), 'A.B.C')
self.assertEqual(sp.num_units(), 3)
self.assertEqual(len(sp.units()), 3)

sp.add_unit(UnitSpecies('D'))
self.assertEqual(sp.serial(), 'A.B.C.D')
self.assertEqual(sp.num_units(), 4)
self.assertEqual(len(sp.units()), 4)

units = sp.units()
self.assertEqual(len(units), 4)
Expand All @@ -63,7 +62,7 @@ def test5(self):
sp = Species('X(a,b=c^1).Y(d=e^1,f=g)')
units = sp.units()

self.assertEqual(sp.num_units(), 2)
self.assertEqual(len(sp.units()), 2)
self.assertEqual(len(units), 2)

self.assertEqual(units[0].name(), 'X')
Expand Down

0 comments on commit 1756134

Please sign in to comment.