English 中文(简体)
Testing complex datatypes?
原标题:

What s are some ways of testing complex data types such as video, images, music, etc. I m using TDD and wonder are there alternatives to "gold file" testing for rendering algorithms. I understand that there s ways to test other parts of the program that don t render and using those results you can infer. However, I m particularly interested in rendering algorithms specifically image/video testing.

The question came up while I was using OpenCV/Python to do some basic facial recognition and want to verify its correctness.

Even if there s nothing definitive any suggestion will help.

最佳回答

The idea how to test rendering is quite simple: to test a function use the inverse function and check if the input and output match (match is not equality in your case):

f(f^-1(x)) = x

To test a rendering algorithm you would encode the raw input, render the encoded values and analyze the difference between the rendered output and the raw input. One problem is to get the raw input, when encoding/decoding random input is not appropriate. Another challenge is to evaluate the differences between the raw input and rendering output. I suppose if you re writing some rendering software you should be able to do a frequency analysis on the data. (Some transformation should pop into your head now.)

If it is possible generate your test data. Text fixtures are a real maintenance problem. They only shine in the beginning. If they are changing in some kind everything breaks down. The main problem is that if your using a fixture your tests are going to repeat the fixture s content. This makes the interpretation of intent of your tests harder. If there is a magic value in your test what s the significant part of this value?

Fixture:

actual = parse("file.xml")
expected = "magic value"
assert(actual == expected)

Generated values:

expected = generate()
input = render(expected)
actual = parse()
assert(actual == expected)

The nice thing with generators is that you can build quite complex object graphs with them starting from primitive types and fields (python Quickcheck version).

Generator based tests are not deterministic by nature. But given enough trials they follow the Law of large numbers.

Their additional value is that they will produce a good test value range coverage. (Which is hard to achieve with test fixtures.) They will find unanticipated bugs in your code.

An alternative test approach is to test with a equivalent function:

f(x) = f (x)

For example if you have a rendering function to compare against. This kind of test approach is useful if you have a working function. This function is your benchmark. It cannot be used in production because it is to slow or does use to much memory but can be easily debugged or proven to be correct.

问题回答

What s wrong with the "gold file" technique? It s part of your test fixture. Every test has a data fixture that s the equivalent to the "gold file" in a media-intensive application.

When doing ordinary TDD of ordinary business applications, one often has a golden database fixture that must be used.

Even when testing simple functions and core classes of an application, the setUp method creates a kind of "gold file" fixture for that class or function.

What s wrong with that technique? Please update your question with the specific problems you re having.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签