473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

set and frozenset unit tests?

I have released interval-0.2.1 at
http://members.cox.net/apoco/interval/. IntervalSet and
FrozenIntervalSet objects are now (as far as I can tell) functionality
equivalent to set and frozenset objects, except they can contain
intervals as well as discrete values.

Though I have my own unit tests for verifying this claim, I'd like to
run my code through actual set and frozenset unit tests. Does any such
code exist? Is it in pure Python? If so, where can it be obtained?

Oh, and again, I'd really appreciate additional feedback on the module,
especially related to design, if you've got any. My goal for this
project is to make the classes built-in-data-type quality.

--
Jacob
Jul 21 '05 #1
5 1807
Jacob Page wrote:
I have released interval-0.2.1 at
http://members.cox.net/apoco/interval/. IntervalSet and
FrozenIntervalSet objects are now (as far as I can tell) functionality
equivalent to set and frozenset objects, except they can contain
intervals as well as discrete values.

Though I have my own unit tests for verifying this claim, I'd like to
run my code through actual set and frozenset unit tests. Does any such
code exist? Is it in pure Python? If so, where can it be obtained?

Oh, and again, I'd really appreciate additional feedback on the module,
especially related to design, if you've got any. My goal for this
project is to make the classes built-in-data-type quality.


Look at /usr/lib/python2.x/test/ (on unix platforms).

Reinhold
Jul 21 '05 #2
Reinhold Birkenfeld wrote:
Jacob Page wrote:
I'd like to
run my code through actual set and frozenset unit tests. Does any such
code exist? Is it in pure Python? If so, where can it be obtained?


Look at /usr/lib/python2.x/test/ (on unix platforms).


Thanks for pointing that to me. For some reason, the Debian package for
python 2.4 doesn't include those tests, but I acquired them from an
alternative source.

Oye, there's quite a number of set and frozenset features that aren't
well-documented that I now need to implement. What a fun chore!
Jul 21 '05 #3
Jacob Page wrote:
Oye, there's quite a number of set and frozenset features that aren't
well-documented that I now need to implement. What a fun chore!


It would be a great help if you could submit appropriate documentation
patches for the areas you don't think are well-documented:

http://sourceforge.net/tracker/?grou...70&atid=305470

STeVe
Jul 21 '05 #4
Steven Bethard wrote:
Jacob Page wrote:
Oye, there's quite a number of set and frozenset features that aren't
well-documented that I now need to implement. What a fun chore!


It would be a great help if you could submit appropriate documentation
patches for the areas you don't think are well-documented:


Hmm, after closer scrutiny, I'm not sure if the documentation really
does need modification. The largest incompatibility between IntervalSet
and set was that my code wasn't enforcing hashability, and that property
of sets actually IS documented. However, there are two minor things I
don't see documented that caught me by surprise:

* Since the <=, <, >, and >= operators raise an exception if the
right-hand operand is not a set or frozenset, it seemed reasonable to
me to assume that == and != should, too. However, the test suite for
sets expect the comparisons to be allowed; == between a set and non-set
return False, != returns True. Seems inconsistent with the rest of the
operators, but then again, the odd use of > and < for purposes other
than ordering also seems strange.

* Apparently, if fs is a frozenset instance, fs.copy() returns a
reference to fs instead of a copy of fs, and frozenset(fs) does the
same. The unit tests also ensure that subclasses of frozenset don't do
this. It makes sense that it's done that way to save on storage space,
but it's not documented that this happens.

Both issues seem to be pretty minor unless you're making functionally
equivalent classes. I'm sure neither one will confuse someone into
using them improperly, so I think it's fine to leave the docs alone.

By the way, IntervalSet and FrozenIntervalSet, when used in place of set
and frozenset, now pass most of the tests. One notable difference
between them is that whereas sets can contain any hashable object,
IntervalSet elements must be both hashable and orderable (implement
__cmp__). Thus, commands like IntervalSet([FrozenIntervalSet(...)])
fail, unlike set([frozenset(...)]).

I've also changed the methods with mixedCase capitalization to
lower_case_with_underscores, as recommended by PEP 8.

Version 0.2.2 of the module can now be downloaded from
http://members.cox.net/apoco/interval/. I'm about to freeze the
interfaces and transition the module to beta, so if you have any
interest in the project or design change ideas, please send feedback soon.
Jul 21 '05 #5
[Jacob Page]
there are two minor things I
don't see documented that caught me by surprise:

* Since the <=, <, >, and >= operators raise an exception if the
right-hand operand is not a set or frozenset, it seemed reasonable to
me to assume that == and != should, too. However, the test suite for
sets expect the comparisons to be allowed; == between a set and non-set
return False, != returns True. Seems inconsistent with the rest of the
operators, but then again, the odd use of > and < for purposes other
than ordering also seems strange.
It is consistent with the rest of Python. It turns out to be somewhat
handy to be able to run an equality test with objects of differing
types:

if x != None: ... # doesn't blow-up is x is a string or number

if 'cat' in [1, 3.1, 'hat']: ... # doesn't blow-up during eq tests

OTOH, the subset/superset tests pretty much require a set to be on both
sides. Welcome to the strange and exciting world of rich comparisons.
* Apparently, if fs is a frozenset instance, fs.copy() returns a
reference to fs instead of a copy of fs, and frozenset(fs) does the
same. The unit tests also ensure that subclasses of frozenset don't do
this. It makes sense that it's done that way to save on storage space,
but it's not documented that this happens.


It is not documented because it is not a guaranteed part of the API.
Most immutables are like this. Whether equivalent strings and numbers
share the same object id is an implementation detail.
Raymond

Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom Verbeure | last post by:
Hello All, so I'm now convinced that unit testing is really the way to go and I want to add it to an existing project. The first thing that I find out, is that, well, it's hard work. Harder than...
2
by: Stefan Behnel | last post by:
Hi! frozenset() doesn't behave as the other immutable empty data types in 2.4: ..>>> '' is '' True ..>>> () is () True ..>>> frozenset() is frozenset() False
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
6
by: Michael Bray | last post by:
I've just inherited a fairly large project with multiple classes. The developer also wrote a huge number of unit tests (using NUnit) to validate that the classes work correctly. However, I don't...
5
by: shuisheng | last post by:
Dear All, I was told that unit test is a powerful tool for progamming. If I am writing a GUI code, is it possible to still using unit test? I have a little experience in using unittest++. But...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
6
by: Vyacheslav Maslov | last post by:
Hi all! I have many many many python unit test, which are used for testing some remote web service. The most important issue here is logging of test execution process and result. I strongly...
5
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I'm working in Visual Studio 2005 Team Edition for Software Developers I've used the wizard under the Test menu to create a bunch of unit tests. When I click "Test -Start Selected Test Project...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.