Hello,
If I want to check my algorithm if it works good in every cases
so can i check very outer cases and then I can conclude that my algorithm works well in all cases?

Dani AI

Generated

A short primer: testing extreme inputs is useful and builds confidence, but it does not prove an algorithm correct for every possible input. asked precisely this; replies from , and pointed toward both testing and formal approaches. Below is a compact, practical path from quick checks to stronger assurance without repeating the earlier examples.

Use a layered, systematic testing strategy. Start with a concise specification and unit/regression tests for representative cases. Add property-based tests so you assert general properties and let a generator try many combinations automatically. Complement those with fuzzing (random/malformed inputs) and automated CI so failures are caught and minimized over time. Two reachable property-testing tools are QuickCheck and Hypothesis. (hackage.haskell.org)

When correctness is important beyond reasonable doubt, consider formal techniques appropriate to the scope. Model-level tools are good for design and concurrency reasoning (for example, TLA+). Program-level verifiers let you prove that code meets a spec (for example, Dafny). For fully machine-checked mathematical proofs you can use proof assistants (Coq/jsCoq). These are heavier but pay off for critical or subtle algorithms. Learn the cost/benefit before committing to a full formalization. (lamport.org)

Practical checklist:

  • write a brief spec and state the key invariants;
  • implement unit tests and property tests;
  • run fuzzing and static analysis in CI;
  • add assertions and defensive checks for malformed inputs;
  • if the algorithm is safety-critical, model or formally verify the core using the tools above.

This combines the QA mindset mentioned earlier with the logical rigor that and hinted at, giving a workable trade-off between effort and assurance.

Recommended Answers

All 6 Replies

Saying perhaps it is and the can, but me does not understand
(courtesy of our favorite translator babelfish)...

This is a QA kind of question.

You should feed your alogorithm data which has:

1. values outside given bounds, like what the sqrt() runtime function does:
It is able able to return NaN or +INFINITY and sets errno=EDOM (unix only).

2. validate output for known value sets, with extremely large/small or postivie/negative values

3. Deliberately try to break the code - if it expects numeric data feed it text instead of numbers, for example. In all cases it should simply return an error, not crash.
It should NOT exit. Whether or not an exit is called depends on the rules of operation of the program, not on an individual function.


Consider reading 'The Pragmatic Programmer' - it explains how functions (algorithms) are supposed to behave when users are trying to feed them data.

First thank you for the good answer :p
secondly i want to ask you something:
if I have an algorithm that solves questions with order of arithmetic operations than my input values can be very long, so I am trying to input something extreme small like:(0+0) or something extreme long and big like:
(2+4*(7/9-(6+7)+(789-9900)+6788-9/(45-998))) and then if my algorithm solves this inputs then I can conclude that my algorithm solves all the inputs i will give him?(and after i will try to input him string and it will not crash)

Member Avatar for Member #46692

Originally quoted by SNA

(2+4*(7/9-(6+7)+(789-9900)+6788-9/(45-998))) and then if my algorithm solves this inputs then I can conclude that my algorithm solves all the inputs i will give him?

Hi,

Just becoz u give ur algorithm this case doesn't mean it works 4 all cases. U might give him many cases and they all appear 2 work. This doesn't not prove him to work it evry case.

For example, there might B 1 case that u forget.

To prove something is not to test alot. But to convince the reader through logic that your answer is the only obtanable solution.

:cool:

OK, I have understood you but you can't check all the cases in the world.

There is something called formal programming or something similar that enables you to state post and preconditions allowing you to "prove" that your code does what you say it does (might have been called formal method)...
This is probably what I was thinking about...
http://en.wikipedia.org/wiki/Formal_method

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.