twa: implement a copy_named_properties_of() method

It was noted in #470 that make_twa_graph did not copy named
properties.  Let's fix that.

* spot/twa/twa.hh, spot/twa/twa.cc (copy_named_properties_of): New
method.
* spot/twa/twagraph.hh (make_twa_graph): Add an extra argument to
call copy_named_properties_of() optionally.
* python/spot/__init__.py (twa_graph.__copy__): Use it.
* tests/python/twagraph.py: Test that.
* tests/sanity/namedprop.test: Ensure copy_named_properties_of copies
all known named properties.
This commit is contained in:
Alexandre Duret-Lutz 2021-07-08 10:30:19 +02:00
parent 0cf2d285b6
commit 31a681c285
6 changed files with 70 additions and 10 deletions

View file

@ -62,10 +62,15 @@ aut.new_acc_edge(0, 1, bddtrue, True)
assert aut.num_edges() == 1 + cpy.num_edges()
aut.prop_universal(True)
aut.set_name("some name")
cpy = spot.make_twa_graph(aut, spot.twa_prop_set(False, False, False,
False, False, False))
assert cpy.prop_universal() != aut.prop_universal()
assert cpy.prop_universal() == spot.trival.maybe()
assert cpy.get_name() == None
cpy = spot.make_twa_graph(aut, spot.twa_prop_set(False, False, False,
False, False, False), True)
assert cpy.get_name() == "some name"
from copy import copy
cpy = copy(aut)
@ -73,6 +78,7 @@ assert aut.to_str() == cpy.to_str()
cpy.set_init_state(1)
assert [2, 1] == list(aut.univ_dests(aut.get_init_state_number()))
assert cpy.get_init_state_number() == 1
assert cpy.get_name() == "some name"
try:
s = aut.state_acc_sets(0)

View file

@ -1,6 +1,6 @@
#! /bin/sh
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Laboratoire de Recherche et Développement de
# Copyright (C) 2017, 2021 Laboratoire de Recherche et Développement de
# l'Epita (LRDE).
#
# This file is part of Spot, a model checking library.
@ -26,6 +26,8 @@
set +x
DOC=doc/org/concepts.org
CPY=spot/twa/twa.cc
err=0
rm -f namedprop.log
@ -40,14 +42,32 @@ for dir in "$TOP/spot" "$TOP/bin" "$TOP/tests"; do
done |
xargs sed -n 's/.*get_named_prop<.*>("\([^"]*\)").*/\1/p
s/.*set_named_prop("\([^"]*\)",.*/\1/p' |
sort | uniq |
sort | uniq > proplist.lst
while read prop; do
if ! grep -q "$prop" "$TOP/$DOC"; then
echo "* $prop" >>namedprop.log
fi
done
done < proplist.lst
if test -f namedprop.log; then
echo "The following named properties are not documented in $DOC:"
cat namedprop.log
exit 1
err=1
fi
rm -f namedprop.log
while read prop; do
if ! grep -q "COPY_PROP.*$prop" "$TOP/$CPY"; then
echo "* $prop" >>namedprop.log
fi
done < proplist.lst
if test -f namedprop.log; then
echo "These properties are not copied by copy_named_properties_of() ($CPY):"
cat namedprop.log
err=1
fi
rm -f namedprop.log proplist.lst
exit $err