¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

[TDD] How do you write tests if you aren't sure what the result should be?


 

Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag and I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of the
formula will be. (How many timer ticks will it take to get to point A?)

This is something that I feel can have tests, and needs tests. But I have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write tests
when I don't know what the results should be, but I know the computer needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47


Donaldson, John
 

Avi, I don't think that's a simple question at all!
I think it's hacking away at the boundary between TDD (a method) and algorithms (invention).

John D.

-----Original Message-----
From: testdrivendevelopment@... [mailto:testdrivendevelopment@...] On Behalf Of Avi Kessner
Sent: 14 February 2013 08:24
To: testdrivendevelopment@...
Cc: robert Merkel
Subject: Re: [TDD] How do you write tests if you aren't sure what the result should be?

Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag and I'm not sure how to continue.
We have some complicated mathematical formulas that interact with each other The math is too complicated for me to resolve easily. These formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of the formula will be. (How many timer ticks will it take to get to point A?)

This is something that I feel can have tests, and needs tests. But I have no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write tests when I don't know what the results should be, but I know the computer needs to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I and the number 47






------------------------------------

Yahoo! Groups Links


 

My actual question is a meta-question by the way. How do I write tests
when I don't know what the results should be,
You can't. You need to compute by hand, or some other means, the expected
result for some input. This should not be impossible. Check the result for
simple cases. For instance, if I were writing a sin function, I would check
sin(0) =0, sin(90)=1, and the like. Check examples from a textbook;
compute the expected result with Mathematica or other mathematical software.

OTOH, if the meta-question is how to *drive* development of a function with
tests, perhaps i would break the function to be developed as a composition
of functions, then test-drive those separately. Or maybe start with a crude
approximation and then refine it as needed. Perhaps your customer does not
need many significant digits. Perhaps you can get away with something
that's only guaranteed to be within the expected order of magnitude. Or use
a combination of both methods.

Any way you look at it, to do TDD you need to be able to come up with
examples of what the system should do given example inputs.


Matteo


 

Hi people!

English is not my mother tongue, so maybe I misunderstood some of your
message, Avi.

Review:

- You have a program, you write it using TDD

Ok?

Then,
- You have complicated formulas, already written, THAT ARE not in your
program, that is, it's not part of what you are writing using TDD, it can
be viewed as a math library you have. Your program will use that ALREADY
written formulas.

or?

- You have complicated formulas, you must use and write in the next piece
of your program

Which is the case? I presume it is the second case, am I right?

Then, you wrote
I need to write a series of functions which predict what the steps of the
formula will be. (How many timer ticks will it take to get to point A?)

WHY? Which is the use case in your program?

I would start with a simple mini use case, then the formula(s) and their
application will evolve in your program.

Can you describe a use case?

I could imagine one program:

- I need to write a physics engine

Instead of testing the results of a multibody gravity evaluation in a
complicated environment, I would start with:

- Given a ball, suspended in air, at time t0 its at y0, then I would test
that at t1 its at y1 with y1 < y0

Angel "Java" Lopez
@ajlopez
gh:ajlopez

On Thu, Feb 14, 2013 at 4:24 AM, Avi Kessner <akessner@...> wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag and I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of the
formula will be. (How many timer ticks will it take to get to point A?)

This is something that I feel can have tests, and needs tests. But I have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write tests
when I don't know what the results should be, but I know the computer needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47

[Non-text portions of this message have been removed]



[Non-text portions of this message have been removed]


Amir Kolsky
 

Do you have the formulae or do you need to develop them?



From: testdrivendevelopment@...
[mailto:testdrivendevelopment@...] On Behalf Of Avi Kessner
Sent: Thursday, February 14, 2013 2:24 AM
To: testdrivendevelopment@...
Cc: robert Merkel
Subject: Re: [TDD] How do you write tests if you aren't sure what the result
should be?





Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag and I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of the
formula will be. (How many timer ticks will it take to get to point A?)

This is something that I feel can have tests, and needs tests. But I have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write tests
when I don't know what the results should be, but I know the computer needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47


 

Hi Avi,

On Thu, Feb 14, 2013 at 2:24 AM, Avi Kessner <akessner@...> wrote:

The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of the
formula will be. (How many timer ticks will it take to get to point A?)
Is it possible to redefine the question? You could gain confidence by
testing the algorithm behaves as expected with given clock values, instead
of having to guess (and have test failures when running the suite on a
machine capable of more operations / tick).


My actual question is a meta-question by the way. How do I write tests
when I don't know what the results should be, but I know the computer needs
to get the "correct" result?

If I do not know what the result should be, I have to assume the
computation provides the "correct" result. At this point I default to
validating the computation - I don't know what the answer will be, but I
know we have to be doing things "this" way. I feel bad resorting to this
(it makes the software brittle and resistant to change), but if I can't
check my work in the future because I don't know what the results should
be, I have to guard the one source of truth I have (the algorithm).

Cheers!
Carl


Pascal Roy
 

I don't think the problem is directly related to TDD per say. Let me rephrase your
question to point out what the real problem is :
"How do you know your computation is right if you're not
even sure what the results should be?"

I would say, it's a pretty fundamental issue...

Pascal Roy
www.elapsetech.com


Le 2013-02-14 ¨¤ 05:57, Angel Java Lopez <ajlopez2000@...> a ¨¦crit :

Hi people!

English is not my mother tongue, so maybe I misunderstood some of your
message, Avi.

Review:

- You have a program, you write it using TDD

Ok?

Then,
- You have complicated formulas, already written, THAT ARE not in your
program, that is, it's not part of what you are writing using TDD, it can
be viewed as a math library you have. Your program will use that ALREADY
written formulas.

or?

- You have complicated formulas, you must use and write in the next piece
of your program

Which is the case? I presume it is the second case, am I right?

Then, you wrote
I need to write a series of functions which predict what the steps of the
formula will be. (How many timer ticks will it take to get to point A?)

WHY? Which is the use case in your program?

I would start with a simple mini use case, then the formula(s) and their
application will evolve in your program.

Can you describe a use case?

I could imagine one program:

- I need to write a physics engine

Instead of testing the results of a multibody gravity evaluation in a
complicated environment, I would start with:

- Given a ball, suspended in air, at time t0 its at y0, then I would test
that at t1 its at y1 with y1 < y0

Angel "Java" Lopez
@ajlopez
gh:ajlopez

On Thu, Feb 14, 2013 at 4:24 AM, Avi Kessner <akessner@...> wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag and I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of the
formula will be. (How many timer ticks will it take to get to point A?)

This is something that I feel can have tests, and needs tests. But I have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write tests
when I don't know what the results should be, but I know the computer needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47

[Non-text portions of this message have been removed]



[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links





[Non-text portions of this message have been removed]


 

Even when the math is complicated, there should be inputs where the results
are easy to hand compute. For example, where the inputs are combinations
of 0s, 1s, -1s, etc. Those trivial cases should be enough to drive
development of properly structured code.

I would depend on customer-level tests to see if the computations are
properly supporting whatever "business" functionality the system is
supposed to deliver. If wrong answers still allows the user to do what
they need to do, then maybe the fancy formulas are overkill anyway.

SteveG

On Thu, Feb 14, 2013 at 12:24 AM, Avi Kessner <akessner@...> wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag and I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of the
formula will be. (How many timer ticks will it take to get to point A?)

This is something that I feel can have tests, and needs tests. But I have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write tests
when I don't know what the results should be, but I know the computer needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47

[Non-text portions of this message have been removed]



[Non-text portions of this message have been removed]


 

Ill write more later when I'm at my desk, but the use case here is matching
and predicting animations

On Feb 14, 2013 5:15 PM, "Steven Gordon" <sgordonphd@...> wrote:

Even when the math is complicated, there should be inputs where the results
are easy to hand compute. For example, where the inputs are combinations
of 0s, 1s, -1s, etc. Those trivial cases should be enough to drive
development of properly structured code.

I would depend on customer-level tests to see if the computations are
properly supporting whatever "business" functionality the system is
supposed to deliver. If wrong answers still allows the user to do what
they need to do, then maybe the fancy formulas are overkill anyway.

SteveG

On Thu, Feb 14, 2013 at 12:24 AM, Avi Kessner <akessner@...> wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag and
I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of the
formula will be. (How many timer ticks will it take to get to point A?)

This is something that I feel can have tests, and needs tests. But I have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write tests
when I don't know what the results should be, but I know the computer
needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47









------------------------------------

Yahoo! Groups Links




 

Hi Avi,

If you had to test your work only by direct observation, what would you
look for?

Charlie


On Thu, Feb 14, 2013 at 7:21 AM, Avi Kessner <akessner@...> wrote:

**


Ill write more later when I'm at my desk, but the use case here is matching
and predicting animations

On Feb 14, 2013 5:15 PM, "Steven Gordon" sgordonphd@...> wrote:

Even when the math is complicated, there should be inputs where the
results
are easy to hand compute. For example, where the inputs are combinations
of 0s, 1s, -1s, etc. Those trivial cases should be enough to drive
development of properly structured code.

I would depend on customer-level tests to see if the computations are
properly supporting whatever "business" functionality the system is
supposed to deliver. If wrong answers still allows the user to do what
they need to do, then maybe the fancy formulas are overkill anyway.

SteveG

On Thu, Feb 14, 2013 at 12:24 AM, Avi Kessner akessner@...> wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag and
I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of
the
formula will be. (How many timer ticks will it take to get to point A?)

This is something that I feel can have tests, and needs tests. But I
have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write tests
when I don't know what the results should be, but I know the computer
needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47

[Non-text portions of this message have been removed]



[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links



[Non-text portions of this message have been removed]



[Non-text portions of this message have been removed]


 

Hi Avi,

I'm not sure whether this is applicable to your situation, but I also had a
case where we were calculating some complex formulas and I couldn't get an
exact result predicted, simply because the system was meant to be able to
calculate those results with more precision than was possible before.

In that situation, we were able to define our (acceptance) tests to accept
approximate values, within a given range. So the expected outcome would for
instance be 0.546 +/- 0.5%
We also had to control some of the inputs to the system, such as the seed
used to generate random values that were used in the calculations, which
would normally change with time.

Is that something that might work in your circumstances?

Wouter

On Thu, Feb 14, 2013 at 5:31 PM, Charlie Poole <charliepoole@...>wrote:

Hi Avi,

If you had to test your work only by direct observation, what would you
look for?

Charlie


On Thu, Feb 14, 2013 at 7:21 AM, Avi Kessner <akessner@...> wrote:

**


Ill write more later when I'm at my desk, but the use case here is
matching
and predicting animations

On Feb 14, 2013 5:15 PM, "Steven Gordon" sgordonphd@...> wrote:

Even when the math is complicated, there should be inputs where the
results
are easy to hand compute. For example, where the inputs are
combinations
of 0s, 1s, -1s, etc. Those trivial cases should be enough to drive
development of properly structured code.

I would depend on customer-level tests to see if the computations are
properly supporting whatever "business" functionality the system is
supposed to deliver. If wrong answers still allows the user to do what
they need to do, then maybe the fancy formulas are overkill anyway.

SteveG

On Thu, Feb 14, 2013 at 12:24 AM, Avi Kessner akessner@...>
wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag
and
I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with
each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic tween
formula)
I need to write a series of functions which predict what the steps of
the
formula will be. (How many timer ticks will it take to get to point
A?)

This is something that I feel can have tests, and needs tests. But I
have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write
tests
when I don't know what the results should be, but I know the computer
needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47









------------------------------------

Yahoo! Groups Links











------------------------------------

Yahoo! Groups Links



--
Wouter Lagerweij | wouter@...
| @wouterla <!/wouterla>


 

Thank you for your help and suggestions so far.
My actual use case is a bit boring, but I found a more fun analogy.
Say you were asked to make a change to a game called Yetti Sport.

The object of the game is that you hit a penguin and it flies across the
screen until it stops bouncing or getting blown up by mines.
The task required is that you place a marker or some graphic on the spot
where the penguin will land at the end of the run. However, the marker
needs to be placed before the spot becomes visible.

This means that you need to use the current state of the game to predict
where the penguin will land, and place a graphic exactly there before all
the animations for the penguin flying through the air are done.

If I was doing this without unit tests, I would run the game wait for it to
keep bouncing for x number of seconds, and see if the marker showed up in
the right place or not. Not a very efficient test.

Ideally however, I don't just want to have acceptance tests that it works,
I also want my tests to help me develop the solution. (aka TDD)
It seems to me that this should be possible (cause it's just math being
done over some variable data etc) but I can't figure out what I'm missing
to make it work. My problem with putting in values such as 0 or 1 is that
while I should get 0 distance with an input of 0, that doesn't actually
help me solve the problem. What do I do for inputs greater than zero?

brought to you by the letters A, V, and I
and the number 47


On Fri, Feb 15, 2013 at 1:23 AM, Wouter Lagerweij <wouter@...>wrote:

**


Hi Avi,

I'm not sure whether this is applicable to your situation, but I also had a
case where we were calculating some complex formulas and I couldn't get an
exact result predicted, simply because the system was meant to be able to
calculate those results with more precision than was possible before.

In that situation, we were able to define our (acceptance) tests to accept
approximate values, within a given range. So the expected outcome would for
instance be 0.546 +/- 0.5%
We also had to control some of the inputs to the system, such as the seed
used to generate random values that were used in the calculations, which
would normally change with time.

Is that something that might work in your circumstances?

Wouter

On Thu, Feb 14, 2013 at 5:31 PM, Charlie Poole charliepoole@...
wrote:

Hi Avi,

If you had to test your work only by direct observation, what would you
look for?

Charlie


On Thu, Feb 14, 2013 at 7:21 AM, Avi Kessner akessner@...> wrote:

**


Ill write more later when I'm at my desk, but the use case here is
matching
and predicting animations

On Feb 14, 2013 5:15 PM, "Steven Gordon" sgordonphd@...> wrote:

Even when the math is complicated, there should be inputs where the
results
are easy to hand compute. For example, where the inputs are
combinations
of 0s, 1s, -1s, etc. Those trivial cases should be enough to drive
development of properly structured code.

I would depend on customer-level tests to see if the computations are
properly supporting whatever "business" functionality the system is
supposed to deliver. If wrong answers still allows the user to do
what
they need to do, then maybe the fancy formulas are overkill anyway.

SteveG

On Thu, Feb 14, 2013 at 12:24 AM, Avi Kessner akessner@...>
wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a snag
and
I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with
each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic
tween
formula)
I need to write a series of functions which predict what the steps
of
the
formula will be. (How many timer ticks will it take to get to point
A?)

This is something that I feel can have tests, and needs tests. But
I
have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write
tests
when I don't know what the results should be, but I know the
computer
needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47

[Non-text portions of this message have been removed]







------------------------------------

Yahoo! Groups Links



[Non-text portions of this message have been removed]







------------------------------------

Yahoo! Groups Links



--
Wouter Lagerweij | wouter@...
| @wouterla !/wouterla>


[Non-text portions of this message have been removed]



[Non-text portions of this message have been removed]


 

Hi people!

Ah! Thanks for the detail, Avi. I have more context. Ok, short phrases,
English is not in my expertise ;-)

If I were to implement something like you describe (I had some similar
projects):

- I should separate the rendering of the game behavior. My tests will have
no rendering test, at least at first iterations
- It should be like coding MVC web applications: you code and develop the
controller using TDD without any view, yet.
- I should test the penguin movement. Penguin at X, run one cycle, then
Penguin at X+dX
- I should test the collision
- I should test the bounce angle
- etc....

Then, when the setting of the test start to be complicated, in one project,
we wrote a DSL language, like:

penguin at x,y
penguin direction a
penguin velocity v
brick at x2,y2
run 3 cycle
then
penguin at x3,y3
penguin direction a'
penguin velocity v'

We wrote many test files, and a test that loads a file, run it, and compare
the final state
(In many projects, I use JSON files (or urggg.... XML ;-), directly, to not
write a DSL parser).

The internal implementation emerged for this evolutive approach, with TDD.
As usual, refactor, back of the envelope design, discussions, etc..

Meanwhile, an spike about rendering the game status.

Angel "Java" Lopez
@ajlopez
gh:ajlopez

On Fri, Feb 15, 2013 at 6:24 AM, Avi Kessner <akessner@...> wrote:

Thank you for your help and suggestions so far.
My actual use case is a bit boring, but I found a more fun analogy.
Say you were asked to make a change to a game called Yetti Sport.

The object of the game is that you hit a penguin and it flies across the
screen until it stops bouncing or getting blown up by mines.
The task required is that you place a marker or some graphic on the spot
where the penguin will land at the end of the run. However, the marker
needs to be placed before the spot becomes visible.

This means that you need to use the current state of the game to predict
where the penguin will land, and place a graphic exactly there before all
the animations for the penguin flying through the air are done.

If I was doing this without unit tests, I would run the game wait for it to
keep bouncing for x number of seconds, and see if the marker showed up in
the right place or not. Not a very efficient test.

Ideally however, I don't just want to have acceptance tests that it works,
I also want my tests to help me develop the solution. (aka TDD)
It seems to me that this should be possible (cause it's just math being
done over some variable data etc) but I can't figure out what I'm missing
to make it work. My problem with putting in values such as 0 or 1 is that
while I should get 0 distance with an input of 0, that doesn't actually
help me solve the problem. What do I do for inputs greater than zero?

brought to you by the letters A, V, and I
and the number 47


On Fri, Feb 15, 2013 at 1:23 AM, Wouter Lagerweij <wouter@...
wrote:
**


Hi Avi,

I'm not sure whether this is applicable to your situation, but I also
had a
case where we were calculating some complex formulas and I couldn't get
an
exact result predicted, simply because the system was meant to be able to
calculate those results with more precision than was possible before.

In that situation, we were able to define our (acceptance) tests to
accept
approximate values, within a given range. So the expected outcome would
for
instance be 0.546 +/- 0.5%
We also had to control some of the inputs to the system, such as the seed
used to generate random values that were used in the calculations, which
would normally change with time.

Is that something that might work in your circumstances?

Wouter

On Thu, Feb 14, 2013 at 5:31 PM, Charlie Poole charliepoole@...
wrote:

Hi Avi,

If you had to test your work only by direct observation, what would you
look for?

Charlie


On Thu, Feb 14, 2013 at 7:21 AM, Avi Kessner akessner@...>
wrote:

**


Ill write more later when I'm at my desk, but the use case here is
matching
and predicting animations

On Feb 14, 2013 5:15 PM, "Steven Gordon" sgordonphd@...>
wrote:

Even when the math is complicated, there should be inputs where the
results
are easy to hand compute. For example, where the inputs are
combinations
of 0s, 1s, -1s, etc. Those trivial cases should be enough to drive
development of properly structured code.

I would depend on customer-level tests to see if the computations
are
properly supporting whatever "business" functionality the system is
supposed to deliver. If wrong answers still allows the user to do
what
they need to do, then maybe the fancy formulas are overkill anyway.

SteveG

On Thu, Feb 14, 2013 at 12:24 AM, Avi Kessner akessner@...>
wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a
snag
and
I'm
not sure how to continue.
We have some complicated mathematical formulas that interact with
each
other The math is too complicated for me to resolve easily. These
formulas are calculated based on time. (For example, an elastic
tween
formula)
I need to write a series of functions which predict what the
steps
of
the
formula will be. (How many timer ticks will it take to get to
point
A?)

This is something that I feel can have tests, and needs tests.
But
I
have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I write
tests
when I don't know what the results should be, but I know the
computer
needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47









------------------------------------

Yahoo! Groups Links











------------------------------------

Yahoo! Groups Links



--
Wouter Lagerweij | wouter@...
| @wouterla !/wouterla>










------------------------------------

Yahoo! Groups Links




 

Hi Angel,
Thanks for what you wrote.

However, I don't understand the last section. I think it is the most
important part!

"We wrote many test files, and a test that loads a file, run it, and compare
the final state
(In many projects, I use JSON files (or urggg.... XML ;-), directly, to not
write a DSL parser).

The internal implementation emerged for this evolutive approach, with TDD.
As usual, refactor, back of the envelope design, discussions, etc..

Meanwhile, an spike about rendering the game status."

How did you get the implementation to evolve from the multiple test files?
How did you write the test files? What is "an spike about rendering game
status"?

brought to you by the letters A, V, and I
and the number 47

On Fri, Feb 15, 2013 at 12:11 PM, Angel Java Lopez <ajlopez2000@...>wrote:

**


Hi people!

Ah! Thanks for the detail, Avi. I have more context. Ok, short phrases,
English is not in my expertise ;-)

If I were to implement something like you describe (I had some similar
projects):

- I should separate the rendering of the game behavior. My tests will have
no rendering test, at least at first iterations
- It should be like coding MVC web applications: you code and develop the
controller using TDD without any view, yet.
- I should test the penguin movement. Penguin at X, run one cycle, then
Penguin at X+dX
- I should test the collision
- I should test the bounce angle
- etc....

Then, when the setting of the test start to be complicated, in one project,
we wrote a DSL language, like:

penguin at x,y
penguin direction a
penguin velocity v
brick at x2,y2
run 3 cycle
then
penguin at x3,y3
penguin direction a'
penguin velocity v'

We wrote many test files, and a test that loads a file, run it, and compare
the final state
(In many projects, I use JSON files (or urggg.... XML ;-), directly, to not
write a DSL parser).

The internal implementation emerged for this evolutive approach, with TDD.
As usual, refactor, back of the envelope design, discussions, etc..

Meanwhile, an spike about rendering the game status.


Angel "Java" Lopez
@ajlopez
gh:ajlopez

On Fri, Feb 15, 2013 at 6:24 AM, Avi Kessner akessner@...> wrote:

Thank you for your help and suggestions so far.
My actual use case is a bit boring, but I found a more fun analogy.
Say you were asked to make a change to a game called Yetti Sport.

The object of the game is that you hit a penguin and it flies across the
screen until it stops bouncing or getting blown up by mines.
The task required is that you place a marker or some graphic on the spot
where the penguin will land at the end of the run. However, the marker
needs to be placed before the spot becomes visible.

This means that you need to use the current state of the game to predict
where the penguin will land, and place a graphic exactly there before all
the animations for the penguin flying through the air are done.

If I was doing this without unit tests, I would run the game wait for it
to
keep bouncing for x number of seconds, and see if the marker showed up in
the right place or not. Not a very efficient test.

Ideally however, I don't just want to have acceptance tests that it
works,
I also want my tests to help me develop the solution. (aka TDD)
It seems to me that this should be possible (cause it's just math being
done over some variable data etc) but I can't figure out what I'm missing
to make it work. My problem with putting in values such as 0 or 1 is that
while I should get 0 distance with an input of 0, that doesn't actually
help me solve the problem. What do I do for inputs greater than zero?

brought to you by the letters A, V, and I
and the number 47


On Fri, Feb 15, 2013 at 1:23 AM, Wouter Lagerweij wouter@...
wrote:
**


Hi Avi,

I'm not sure whether this is applicable to your situation, but I also
had a
case where we were calculating some complex formulas and I couldn't get
an
exact result predicted, simply because the system was meant to be able
to
calculate those results with more precision than was possible before.

In that situation, we were able to define our (acceptance) tests to
accept
approximate values, within a given range. So the expected outcome would
for
instance be 0.546 +/- 0.5%
We also had to control some of the inputs to the system, such as the
seed
used to generate random values that were used in the calculations,
which
would normally change with time.

Is that something that might work in your circumstances?

Wouter

On Thu, Feb 14, 2013 at 5:31 PM, Charlie Poole charliepoole@...
wrote:

Hi Avi,

If you had to test your work only by direct observation, what would
you
look for?

Charlie


On Thu, Feb 14, 2013 at 7:21 AM, Avi Kessner akessner@...>
wrote:

**


Ill write more later when I'm at my desk, but the use case here is
matching
and predicting animations

On Feb 14, 2013 5:15 PM, "Steven Gordon" sgordonphd@...>
wrote:

Even when the math is complicated, there should be inputs where
the
results
are easy to hand compute. For example, where the inputs are
combinations
of 0s, 1s, -1s, etc. Those trivial cases should be enough to
drive
development of properly structured code.

I would depend on customer-level tests to see if the computations
are
properly supporting whatever "business" functionality the system
is
supposed to deliver. If wrong answers still allows the user to do
what
they need to do, then maybe the fancy formulas are overkill
anyway.

SteveG

On Thu, Feb 14, 2013 at 12:24 AM, Avi Kessner akessner@...
wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a
snag
and
I'm
not sure how to continue.
We have some complicated mathematical formulas that interact
with
each
other The math is too complicated for me to resolve easily.
These
formulas are calculated based on time. (For example, an elastic
tween
formula)
I need to write a series of functions which predict what the
steps
of
the
formula will be. (How many timer ticks will it take to get to
point
A?)

This is something that I feel can have tests, and needs tests.
But
I
have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I
write
tests
when I don't know what the results should be, but I know the
computer
needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47





[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links







[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links



--
Wouter Lagerweij | wouter@...
| @wouterla !/wouterla>










------------------------------------

Yahoo! Groups Links



[Non-text portions of this message have been removed]



Amir Kolsky
 

It still seems to me that you're trying to use TDD to derive the equations.
The programming departments are sometimes called R&D departments.
The last D is the same last D in TDD.
Research (and you are trying to derive the formulae here, not just use them)
can be guided by a test to the extent that you will know when you have
researched a GOOD ENOUGH solution.

Consider the Rubik cube. Can you TDD a program to solve it? If you do not
have an algorithm to implement, you will need to enumerate all possible cube
scenarios and figure out how to solve each one. You could hard code each
solution, but if you wanted a more elegant solution you will need to step
away from the keyboard, and really UNDERSTAND what the problem is.

I think that this is your problem right now. TDD is not a substitute for
understanding the problem domain. You cannot hope to start doing TDD and
hope things will sort out. TDD will ensure that your implementation of the
solution will be correct and complete and that your design is of a high
quality. It will not TEACH you what the domain is.

Sorry :-(
Amir

-----Original Message-----
From: testdrivendevelopment@...
[mailto:testdrivendevelopment@...] On Behalf Of Avi Kessner
Sent: Friday, February 15, 2013 6:31 AM
To: testdrivendevelopment@...
Subject: Re: [TDD] How do you write tests if you aren't sure what the result
should be?

Hi Angel,
Thanks for what you wrote.

However, I don't understand the last section. I think it is the most
important part!

"We wrote many test files, and a test that loads a file, run it, and compare
the final state (In many projects, I use JSON files (or urggg.... XML ;-),
directly, to not write a DSL parser).

The internal implementation emerged for this evolutive approach, with TDD.
As usual, refactor, back of the envelope design, discussions, etc..

Meanwhile, an spike about rendering the game status."

How did you get the implementation to evolve from the multiple test files?
How did you write the test files? What is "an spike about rendering game
status"?

brought to you by the letters A, V, and I and the number 47


On Fri, Feb 15, 2013 at 12:11 PM, Angel Java Lopez
<ajlopez2000@...>wrote:

**


Hi people!

Ah! Thanks for the detail, Avi. I have more context. Ok, short
phrases, English is not in my expertise ;-)

If I were to implement something like you describe (I had some similar
projects):

- I should separate the rendering of the game behavior. My tests will
have no rendering test, at least at first iterations
- It should be like coding MVC web applications: you code and develop
the controller using TDD without any view, yet.
- I should test the penguin movement. Penguin at X, run one cycle,
then Penguin at X+dX
- I should test the collision
- I should test the bounce angle
- etc....

Then, when the setting of the test start to be complicated, in one
project, we wrote a DSL language, like:

penguin at x,y
penguin direction a
penguin velocity v
brick at x2,y2
run 3 cycle
then
penguin at x3,y3
penguin direction a'
penguin velocity v'

We wrote many test files, and a test that loads a file, run it, and
compare the final state (In many projects, I use JSON files (or
urggg.... XML ;-), directly, to not write a DSL parser).

The internal implementation emerged for this evolutive approach, with TDD.
As usual, refactor, back of the envelope design, discussions, etc..

Meanwhile, an spike about rendering the game status.


Angel "Java" Lopez
@ajlopez
gh:ajlopez

On Fri, Feb 15, 2013 at 6:24 AM, Avi Kessner akessner@...> wrote:

Thank you for your help and suggestions so far.
My actual use case is a bit boring, but I found a more fun analogy.
Say you were asked to make a change to a game called Yetti Sport.

The object of the game is that you hit a penguin and it flies across
the screen until it stops bouncing or getting blown up by mines.
The task required is that you place a marker or some graphic on the
spot where the penguin will land at the end of the run. However, the
marker needs to be placed before the spot becomes visible.

This means that you need to use the current state of the game to
predict where the penguin will land, and place a graphic exactly
there before all the animations for the penguin flying through the air
are done.

If I was doing this without unit tests, I would run the game wait
for it
to
keep bouncing for x number of seconds, and see if the marker showed
up in the right place or not. Not a very efficient test.

Ideally however, I don't just want to have acceptance tests that it
works,
I also want my tests to help me develop the solution. (aka TDD) It
seems to me that this should be possible (cause it's just math being
done over some variable data etc) but I can't figure out what I'm
missing to make it work. My problem with putting in values such as 0
or 1 is that while I should get 0 distance with an input of 0, that
doesn't actually help me solve the problem. What do I do for inputs
greater than zero?

brought to you by the letters A, V, and I and the number 47


On Fri, Feb 15, 2013 at 1:23 AM, Wouter Lagerweij wouter@...
wrote:
**


Hi Avi,

I'm not sure whether this is applicable to your situation, but I also
had a
case where we were calculating some complex formulas and I couldn't
get
an
exact result predicted, simply because the system was meant to be able
to
calculate those results with more precision than was possible before.

In that situation, we were able to define our (acceptance) tests to
accept
approximate values, within a given range. So the expected outcome
would
for
instance be 0.546 +/- 0.5%
We also had to control some of the inputs to the system, such as the
seed
used to generate random values that were used in the calculations,
which
would normally change with time.

Is that something that might work in your circumstances?

Wouter

On Thu, Feb 14, 2013 at 5:31 PM, Charlie Poole charliepoole@...
wrote:

Hi Avi,

If you had to test your work only by direct observation, what would
you
look for?

Charlie


On Thu, Feb 14, 2013 at 7:21 AM, Avi Kessner akessner@...>
wrote:

**


Ill write more later when I'm at my desk, but the use case here is
matching
and predicting animations

On Feb 14, 2013 5:15 PM, "Steven Gordon" sgordonphd@...>
wrote:

Even when the math is complicated, there should be inputs where
the
results
are easy to hand compute. For example, where the inputs are
combinations
of 0s, 1s, -1s, etc. Those trivial cases should be enough to
drive
development of properly structured code.

I would depend on customer-level tests to see if the
computations
are
properly supporting whatever "business" functionality the system
is
supposed to deliver. If wrong answers still allows the user to
do
what
they need to do, then maybe the fancy formulas are overkill
anyway.

SteveG

On Thu, Feb 14, 2013 at 12:24 AM, Avi Kessner akessner@...
wrote:

**


Hi, I have a simple question.
I've been developing my program with TDD however I have hit a
snag
and
I'm
not sure how to continue.
We have some complicated mathematical formulas that interact
with
each
other The math is too complicated for me to resolve easily.
These
formulas are calculated based on time. (For example, an
elastic
tween
formula)
I need to write a series of functions which predict what the
steps
of
the
formula will be. (How many timer ticks will it take to get to
point
A?)

This is something that I feel can have tests, and needs tests.
But
I
have
no idea what to check or how to know if the test is correct.

My actual question is a meta-question by the way. How do I
write
tests
when I don't know what the results should be, but I know the
computer
needs
to get the "correct" result?

Thanks.

brought to you by the letters A, V, and I
and the number 47









------------------------------------

Yahoo! Groups Links











------------------------------------

Yahoo! Groups Links



--
Wouter Lagerweij | wouter@...
| @wouterla !/wouterla>










------------------------------------

Yahoo! Groups Links











------------------------------------

Yahoo! Groups Links


Donaldson, John
 

Avi47,

One thing that tells you this is going to be hard is the name of the test.
In this case, I keep getting names like this:
- When_The_Penguin_Is_Hit_Hard_It_Bounces_Many_Times_And_Lands_A_Long_Way_Away

Hmmm!

In TDD we are often just focusing on edge cases - but you are exploring a whole field of possibilities.
I wonder if the field varies smoothly? In that case you might be able to interpolate the predicted outcomes?
(Somewhere between a hard hit and a medium hit the penguin bounces less and goes half way...)

John D.

-----Original Message-----
From: testdrivendevelopment@... [mailto:testdrivendevelopment@...] On Behalf Of Avi Kessner
Sent: 15 February 2013 10:25
To: testdrivendevelopment@...
Subject: Re: [TDD] How do you write tests if you aren't sure what the result should be?

Thank you for your help and suggestions so far.
My actual use case is a bit boring, but I found a more fun analogy.
Say you were asked to make a change to a game called Yetti Sport.

The object of the game is that you hit a penguin and it flies across the screen until it stops bouncing or getting blown up by mines.
The task required is that you place a marker or some graphic on the spot where the penguin will land at the end of the run. However, the marker needs to be placed before the spot becomes visible.

This means that you need to use the current state of the game to predict where the penguin will land, and place a graphic exactly there before all the animations for the penguin flying through the air are done.

If I was doing this without unit tests, I would run the game wait for it to keep bouncing for x number of seconds, and see if the marker showed up in the right place or not. Not a very efficient test.

Ideally however, I don't just want to have acceptance tests that it works, I also want my tests to help me develop the solution. (aka TDD) It seems to me that this should be possible (cause it's just math being done over some variable data etc) but I can't figure out what I'm missing to make it work. My problem with putting in values such as 0 or 1 is that while I should get 0 distance with an input of 0, that doesn't actually help me solve the problem. What do I do for inputs greater than zero?

brought to you by the letters A, V, and I and the number 47


sh
 

Hi Avi,

I'm still new to TDD and I'm not sure, if I really understand your
specific problem, so maybe this is rubbish not how it should be done.
I'll try anyway:

If I understand this correctly, there is no trivial algorithm to compute
the position of the marker, because the 'algorithm' is the behaviour of
the game engine, isn't it?
So the position of the marker is determined by the level design, the
collision detection (or physics system and properties like gravity) of
the game engine and the game objects' properties (velocity, friction, ?)
over time.

If that is correct, it should be possible to write a top-down test like
this (for your example):

// pseudo code
penguin = new GameObject( position, velocity, rotation, shape, whatever );

// let's say physicsWorld computes the position and collisions of the
gameObjects
physicsWorld.add( penguin );

// deltaTime in Milliseconds
fixedDeltaTimeMS = 20;
numFrames = 100;

// evaluate the position for the next two seconds
for ( i=0; i < numFrames; i++ ) {
physicsWorld.update( fixedDeltaTimeMS );
}

// check the position of our hero
assert( penguin.position, whereEverYouWantItToBe );


If you can test like this, you can break the tests down:

shouldMove100PixelWithVelocity100PerSecond();
shouldBounceFiveTimesInSixSecondsWhenFallingFromHeight200(); // whatever :)

If your systems allow testing like this, it should always be possible to
"peek into the future" to determine the position of a game object in x
milliseconds. And then it is not be too complicated to determine whether
the marker is onscreen or offscreen.

Hth,
Stefan


 

"// check the position of our hero
assert( penguin.position, whereEverYouWantItToBe );"

Yes, that is exactly what I want to know :) I don't know where I want the
penguin to end up.

What I have done for now is to "cheat". I create a new scene where the
penguin always ends up on the mark that I have displayed, and I use the
current velocity to decide when to add this scene to the end of the
animation. I don't like this solution for multiple reasons, one of
those problems is that the penguin is now flying for slightly longer than
it's supposed to. I came to the group seeing if there are "proper" ways
to solving this sort of problem. The creation of multiple scenarios and
test files sounds like it's the right direction, but I'm unclear on how
that goal would work.

It doesn't seem right to me that proper TDD would require that I cheat at
my requirements :)

"One thing that tells you this is going to be hard is the name of the test
In this case, I keep getting names like this:
- When_The_Penguin_Is_Hit_Hard_It_Bounces_Many_Times_And_
Lands_A_Long_Way_Away

Hmmm!

That is a very excellent point!


quote cut short for brevity...
" It will not TEACH you what the domain is.

Sorry :-(
Amir "

All very good points. Part of the problem here is that I feel that it's
not just laziness that causes me to not properly know the domain, (though
that can certainly be part of it) but also, I think in essence
the solution isn't knowable. Because of various speeds of computers,
rendering time, inaccuracy of timers etc. This reminds me of the Theta
notation for algorithms, and makes me wonder if you can write unit tests
when the information is so inherently fuzzy. Surely it must be possible.


brought to you by the letters A, V, and I
and the number 47

On Fri, Feb 15, 2013 at 3:36 PM, sh <shvfn@...> wrote:

**


Hi Avi,

I'm still new to TDD and I'm not sure, if I really understand your
specific problem, so maybe this is rubbish not how it should be done.
I'll try anyway:

If I understand this correctly, there is no trivial algorithm to compute
the position of the marker, because the 'algorithm' is the behaviour of
the game engine, isn't it?
So the position of the marker is determined by the level design, the
collision detection (or physics system and properties like gravity) of
the game engine and the game objects' properties (velocity, friction, ?)
over time.

If that is correct, it should be possible to write a top-down test like
this (for your example):

// pseudo code
penguin = new GameObject( position, velocity, rotation, shape, whatever );

// let's say physicsWorld computes the position and collisions of the
gameObjects
physicsWorld.add( penguin );

// deltaTime in Milliseconds
fixedDeltaTimeMS = 20;
numFrames = 100;

// evaluate the position for the next two seconds
for ( i=0; i < numFrames; i++ ) {
physicsWorld.update( fixedDeltaTimeMS );
}

// check the position of our hero
assert( penguin.position, whereEverYouWantItToBe );

If you can test like this, you can break the tests down:

shouldMove100PixelWithVelocity100PerSecond();
shouldBounceFiveTimesInSixSecondsWhenFallingFromHeight200(); // whatever :)

If your systems allow testing like this, it should always be possible to
"peek into the future" to determine the position of a game object in x
milliseconds. And then it is not be too complicated to determine whether
the marker is onscreen or offscreen.

Hth,
Stefan






 

As has already been suggested, it potentially sounds like there is a lack of adequate separation of front-end from the underlying model, which is making it difficult to have practical tests.

You say:

<<If I was doing this without unit tests, I would run the game wait for it to keep bouncing for x number of seconds, and see if the marker showed up in the right place or not. Not a very efficient test.>>

Im not certain I understand what you mean here, but if I do get you, then if your UI is decoupled from the underlying (gravity?) model, why not just compute the sequence of steps (according to some test 'script' of actions) as fast as possible, not in real time? It might be reasonable to have an acceptance test where you have some dummy timer that operates as fast as computer can operate rather than according to some actual temporal clock - since I don't see how this affects the functioning of the program?

You can achieve this through dependency injection and mocks (test doubles) - depending on how you intend to design it. So for example, you might consider having a dummy game clock that just works as fast as the processor can run, while the game clock you use in production is synchronised to some real clock. In your acceptance test, you would use this dummy clock, so that the test runs faster than real-time?

Daz

On 15/02/13 14:48, Avi Kessner wrote:
"// check the position of our hero
assert( penguin.position, whereEverYouWantItToBe );"

Yes, that is exactly what I want to know :) I don't know where I want the
penguin to end up.

What I have done for now is to "cheat". I create a new scene where the
penguin always ends up on the mark that I have displayed, and I use the
current velocity to decide when to add this scene to the end of the
animation. I don't like this solution for multiple reasons, one of
those problems is that the penguin is now flying for slightly longer than
it's supposed to. I came to the group seeing if there are "proper" ways
to solving this sort of problem. The creation of multiple scenarios and
test files sounds like it's the right direction, but I'm unclear on how
that goal would work.

It doesn't seem right to me that proper TDD would require that I cheat at
my requirements :)

"One thing that tells you this is going to be hard is the name of the test
In this case, I keep getting names like this:
- When_The_Penguin_Is_Hit_Hard_It_Bounces_Many_Times_And_
Lands_A_Long_Way_Away

Hmmm!

That is a very excellent point!


quote cut short for brevity...
" It will not TEACH you what the domain is.

Sorry :-(
Amir "

All very good points. Part of the problem here is that I feel that it's
not just laziness that causes me to not properly know the domain, (though
that can certainly be part of it) but also, I think in essence
the solution isn't knowable. Because of various speeds of computers,
rendering time, inaccuracy of timers etc. This reminds me of the Theta
notation for algorithms, and makes me wonder if you can write unit tests
when the information is so inherently fuzzy. Surely it must be possible.


brought to you by the letters A, V, and I
and the number 47


On Fri, Feb 15, 2013 at 3:36 PM, sh <shvfn@...> wrote:

**


Hi Avi,

I'm still new to TDD and I'm not sure, if I really understand your
specific problem, so maybe this is rubbish not how it should be done.
I'll try anyway:

If I understand this correctly, there is no trivial algorithm to compute
the position of the marker, because the 'algorithm' is the behaviour of
the game engine, isn't it?
So the position of the marker is determined by the level design, the
collision detection (or physics system and properties like gravity) of
the game engine and the game objects' properties (velocity, friction, ?)
over time.

If that is correct, it should be possible to write a top-down test like
this (for your example):

// pseudo code
penguin = new GameObject( position, velocity, rotation, shape, whatever );

// let's say physicsWorld computes the position and collisions of the
gameObjects
physicsWorld.add( penguin );

// deltaTime in Milliseconds
fixedDeltaTimeMS = 20;ation, we were able to define our
numFrames = 100;

// evaluate the position for the next two seconds
for ( i=0; i < numFrames; i++ ) {
physicsWorld.update( fixedDeltaTimeMS );
}

// check the position of our hero
assert( penguin.position, whereEverYouWantItToBe );

If you can test like this, you can break the tests down:

shouldMove100PixelWithVelocity100PerSecond();
shouldBounceFiveTimesInSixSecondsWhenFallingFromHeight200(); // whatever :)

If your systems allow testing like this, it should always be possible to
"peek into the future" to determine the position of a game object in x
milliseconds. And then it is not be too complicated to determine whether
the marker is onscreen or offscreen.

Hth,
Stefan








------------------------------------

Yahoo! Groups Links



 

Avi,

I think you are expecting something unrealistic from TDD.

TDDing only facilitates 2 things:
1. Verifying that the code does what the programmer thinks the code should
do.
2. Growing the code in a way that makes the code testable, expressive and
well-factored.

TDD (and unit tests in general) will NOT verify that what the programmer
thinks the code should do actually solves the problem correctly. That is
why we have customers, customer tests and feedback on frequent deliveries
of working software.

If you do not have any idea how to solve the problem, TDD will not
magically lead you to a solution. If you do have an idea, then TDD will
only help you verify that you implemented YOUR idea faithfully and that the
code is well structured.

------------------------------------------------------------------------------------------

I also agree with what I think that others have said about your specific
problem: The engine should be responsible for this functionality, not some
independently developed code. The engine should be able to "predict" what
is would do by running its own functions to simulate what it would do. Why
reinvent the algorithms that the engine already implements? Even if a
faster, less accurate prediction is required than simulating the full
engine algorithm, the engine code and its developers will have a much
better start on seeing what can be left out and still return a good enough
estimation.

Steven Gordon