Re: singleton vs static

From: Rob (nospam_at_nonexistant.com)
Date: 05/30/04


Date: Sun, 30 May 2004 23:36:58 +0930


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:2htktrFgvimaU1@uni-berlin.de...
> Michael Rauscher wrote:
>
> > Dmitry A. Kazakov schrieb:
> >> On Thu, 27 May 2004 09:27:24 -0500, Robert C. Martin
> >> <unclebob@objectmentor.com> wrote:
> >>>Kay is wrong about this. There *are* code structures that are hard to
> >>>test, but it is *always* possible to write code that is testable.
> >>>Indeed, if you write the tests first, you guarantee this.
> >>
> >> Quite interesting. Consider a program that evaluates Pi in decimal
> >> representation continuously digit by digit. How would you test that
> >> program and what does it mean "to test" a program that never ends?

Usually it would mean defining tests to confirm particular sets of
operations are completed correctly, under required conditions. The
trick is sufficient analysis so that one can say "it passed these tests, so
it will be correct when doing X as well".

> >
> > To test something there must be something to test ;-)
> >
> > If the program doesn't produce any output (return values, displaying
> > values etc.) and runs forever, it's useless and there's nothing to test.
>
> Indeed, I remember somebody said something like: "never test for errors
you
> cannot fix." (:-))

Or, "never test for errors that you don't intend to fix".

>
> > If your program produces output
>
> Yes, it broadcasts the digits to Martians...
>
> > (e.g. displays the computet number after
> > n digits) then the program obviously uses an algorithm that doesn't run
> > indefinitely. In this case, this might be an algorithm that returns n
> > digits of PI. As an algorithm must terminate, one can put it into a
> > function and use this function from the "never ending" loop.
> >
> > So, you can test this function.
>
> For a given n, but not for all n. You can consider even simplier example,
a
> program that compares two C-strings. You can test whether the if-statement
> is correct for all possible combinations of charactes, but you cannot test
> the infinite loop containing "if".

You don't actually need to. All you need is sufficient analysis to be able
to ensure that, for each iteration, certain conditions cannot be violated.

In mathematics, there is a notion of an inductive proof. Prove something
for some fixed value (say N). Then provide a proof that, if required
behaviour
is observed for n, that the required behaviour will be observed for n+1.

Such an approach can be used to guide testing. If you can prove that a
successful
test involving one time through the loop is sufficient to conclude that the
test
will be passed for some arbitrary number of times through the loop, then
only one test is needed to verify behaviour of an infinite loop.

>
> There are two things tests cannot deal with: infinity and randomness.
>

Not true. randomness implies that a test is not necessarily repeatable,
in the sense (for example) that the output value varies with each test.
But it may be repeatable, in the sense of ensuring that the output value
is in within some set (or range) of values.



Relevant Pages

  • Re: Why to call it pseudorandom?
    ... >>If an algorithm produces a infinte sequence of digits that never ... >>falls into a loop and passes the most stringent statistical tests ... > an algorithm then they're not unpredictable. ... all computer randgenerators loop. ...
    (sci.math)
  • "Algorithmic Randomness, Quantum Physics, and Incompleteness"
    ... all finite sequences are to be found infinitely often and ... different members of the infinite set of random numbers. ... Just using random numbers with initial digits 1 thru 9, ... it generated by a shorter input algorithm than the length ...
    (sci.logic)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... and Richard made it clear that he understands the order ... >> of evaluation of a for loop. ... > using strlen but using an Oalgorithm when there is a trivial O ... >> In most other languages the terminating ...
    (comp.programming)
  • Re: Efficiency questions: combined ifs and looping 4 times
    ... Choice of algorithm always has a far bigger impact in performance than ... Use sizeof before the loop, store the result in a var and use ... speaks well of PHP. ... your order of complexity analysis is off. ...
    (comp.lang.php)
  • Re: BigNum -- Floating Point
    ... > It means the memory required for representing a number is just ... write an RSA algorithm, for example. ... interest might be something like pi...in base N...to M digits. ... >> wouldn't the gcd() itself need to be able to handle bigints? ...
    (comp.programming)