2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-20 16:52:15 +00:00
Files
python/test/test_set_plain.py
Raoul Gough f7c034d510 New file for v2 of the indexing suite
[SVN r20294]
2003-10-07 17:48:27 +00:00

78 lines
1.8 KiB
Python

#!/usr/bin/python
# -*- mode:python -*-
#
# Python module test_set_plain.py
#
# Doctest-based testing for a C++ set.
#
# Copyright (c) 2003 Raoul M. Gough
#
# Use, modification and distribution is subject to the Boost Software
# License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
# at http://www.boost.org/LICENSE_1_0.txt)
#
# History
# =======
# 2003/10/ 1 rmg File creation
#
# $Id$
#
'''>>> from testnonlinear import *
>>> setTrace(0)
>>> s = Set() # std::set<std::string>
>>> s["hello"] = None # Insert entry (weird interface)
>>> print s["hello"] # Lookup entry
hello
>>> s.insert ("Barnaby") # Insert entry (sensible interface)
>>> print s["Barnaby"]
Barnaby
>>> assert s.has_key ("Barnaby")
>>> assert not s.has_key ("Rudge")
>>> assert "hello" in s
>>> assert "Barnaby" in s
>>> print s.count ("Barnaby")
1
>>> s.insert ("world")
>>> print s["world"]
world
>>> try:
... s.insert ("Barnaby")
... except ValueError, e:
... print "Got expected exception:", e
...
Got expected exception: Set already holds value for insertion
>>> del s["Barnaby"]
>>> try:
... print s["Barnaby"]
... except ValueError, e:
... print "Got expected exception:", e
...
Got expected exception: associative container: key not found
>>> try:
... del s["Barnaby"]
... except ValueError, e:
... print "Got expected exception:", e
...
Got expected exception: Container does not hold value to be erased
>>> print s["hello"]
hello
>>> print s["world"]
world
>>> print [ x for x in s ]
['hello', 'world']
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print 'running...'
import sys
sys.exit(run()[0])