Jump to content

Software Testing a C program (Can't see anything wrong)

Right this topic i'm doing is about software testing. So I have this specification which reads:

 

  1. Average Calculation Program

    This program inputs three (int) values and then asks the user to enter the arithmetic mean (a float value). Then the program calculates the actual mean and checks to see if the user got the answer correct.

    Link to the source code is here: mean.c

    Study the program's specification and source code. Then write down your list of test cases before you compile and run the program. Now test your program against your test cases and record the results. Do you find any errors in the code? If so, make corrections, and then re-try all the test cases. (This is important in case your changes have broken something that used to work.)

     

    So I have the source code here:

    #include <stdio.h>int main(){    int v1, v2, v3;    float user_mean, actual_mean;    printf("Enter 1st value : ");    scanf(" %i", &v1);    printf("Enter 2nd value : ");    scanf(" %i", &v2);    printf("Enter 3rd value : ");    scanf(" %i", &v3);    printf("What is the mean? ");    scanf(" %f", &user_mean);    if (user_mean == (actual_mean = (v1 + v2 + v3) / 3.0))        printf("Correct.  Well done!\n");	    else        printf("Sorry, should be %f\n", actual_mean);        return 0;}//If user enters three values = What is the mean? message (PASS)//If user_mean is correct = Correct well done! message (PASS)//If user_mean is incorrect = Sorry, should be N value message (PASS)//If user_mean = !%f = Error message (FAIL)

    I can't really find that much wrong with it at all. You can see my tests at the bottom in comments.

     

    The only thing i can possibly see wrong is that the user_mean allows for intgers to be entered. but i'm not sure really.

     

    Here is the output of the program for both a correct and incorrect answer:

     

    Can anyone see anything wrong with the program? I mean it's really simple, but this is all about testing software.

     

     

 

post-225550-0-30598300-1453033725.png

   
   
Link to comment
Share on other sites

Link to post
Share on other sites

Why...do you learn C? School?

Lenovo/IBM ThinkPad T61 Widescreen 15.4" 1680x1050
Intel Core2Duo T8300 2.4GHz | 3GB DDR2 from Hynix | SATA II Patched bios (Middleton) | Samsung EVO 850
Arch Linux | Linux 4.3.X x86_64

Link to comment
Share on other sites

Link to post
Share on other sites

dont use floats but ints?

Well if you read the requirements "enter the arithmetic mean (a float value)" I don't think I should change it to integers really. This is about reading a spec and testing to make sure you can meet that spec. The program is really simple I know. But it's about testing a spec.

   
   
Link to comment
Share on other sites

Link to post
Share on other sites

Why...do you learn C? School?

Why is that a problem? From what I understand a lot of languages are based off C. So if you know C you know a lot of other languages already. Such as Java, C#, C++ the list goes on.

   
   
Link to comment
Share on other sites

Link to post
Share on other sites

Why is that a problem? From what I understand a lot of languages are based off C. So if you know C you know a lot of other languages already. Such as Java, C#, C++ the list goes on.

C is rarely used by itself nowadays. A lot of languages are based off it, but C code =/= Java code. The only language where C is automatically correct code is C++

Link to comment
Share on other sites

Link to post
Share on other sites

I'm not sure, what's the issue? What are you trying to do and what's going wrong?

From the picture you posted it looks like you got it working already.

Link to comment
Share on other sites

Link to post
Share on other sites

And what's wrong?

Ah , you need to find mistakes.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

What you have written in the comments of the code are not tests. They are what you think will happen.

 

You actually need to write some test cases and assert that the program produces the expected result.

Link to comment
Share on other sites

Link to post
Share on other sites

C is rarely used by itself nowadays. A lot of languages are based off it, but C code =/= Java code. The only language where C is automatically correct code is C++

Well that's not true at all.

Link to comment
Share on other sites

Link to post
Share on other sites

C is rarely used by itself nowadays. A lot of languages are based off it, but C code =/= Java code. The only language where C is automatically correct code is C++

C is still widely used.

Link to comment
Share on other sites

Link to post
Share on other sites

Why is that a problem? From what I understand a lot of languages are based off C. So if you know C you know a lot of other languages already. Such as Java, C#, C++ the list goes on.

No you...you don't.

Basically with the standard C library you can't write anything. To write a simple GUI program with C it takes a extremely long time and a lot of code. C is old.

Try Python first, or Ruby. There is a reason other languages exist, if C was so superior for everything every program would be written in C.

Lenovo/IBM ThinkPad T61 Widescreen 15.4" 1680x1050
Intel Core2Duo T8300 2.4GHz | 3GB DDR2 from Hynix | SATA II Patched bios (Middleton) | Samsung EVO 850
Arch Linux | Linux 4.3.X x86_64

Link to comment
Share on other sites

Link to post
Share on other sites

Well that's not true at all.

 

 

C is still widely used.

C is widely used. 

C is rarely written.

Lenovo/IBM ThinkPad T61 Widescreen 15.4" 1680x1050
Intel Core2Duo T8300 2.4GHz | 3GB DDR2 from Hynix | SATA II Patched bios (Middleton) | Samsung EVO 850
Arch Linux | Linux 4.3.X x86_64

Link to comment
Share on other sites

Link to post
Share on other sites

No you...you don't.

Basically with the standard C library you can't write anything. To write a simple GUI program with C it takes a extremely long time and a lot of code. C is old.

Try Python first, or Ruby. There is a reason other languages exist, if C was so superior for everything every program would be written in C.

C is great for beginners to learn programming as a whole. Minus the Object Oriented paradigm.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

C is great for beginners to learn programming as a whole. Minus the Object Oriented paradigm.

To learn programming, yes. To build advanced applications, uhm sorry, no.

 

Lenovo/IBM ThinkPad T61 Widescreen 15.4" 1680x1050
Intel Core2Duo T8300 2.4GHz | 3GB DDR2 from Hynix | SATA II Patched bios (Middleton) | Samsung EVO 850
Arch Linux | Linux 4.3.X x86_64

Link to comment
Share on other sites

Link to post
Share on other sites

To learn programming, yes. To build advanced applications, uhm sorry, no.

 

Actually...operating systems are built mainly on C, and I wouldn't say those aren't advanced pieces of programming. Still , they would have probably used something else if they had a better choice.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Try Python first, or Ruby. There is a reason other languages exist, if C was so superior for everything every program would be written in C.

There is no perfect language, every language has its pros and cons.

Link to comment
Share on other sites

Link to post
Share on other sites

Actually...operating systems are built mainly on C, and I wouldn't say those aren't advanced pieces of programming. Still , they would have probably used something else if they had a better choice.

I know. Linux is 100% C. But there is my point, Linux took 10 years to develop to become useable and modern enough to support exotic hardware. So took Windows.

C is wasting time imo

Lenovo/IBM ThinkPad T61 Widescreen 15.4" 1680x1050
Intel Core2Duo T8300 2.4GHz | 3GB DDR2 from Hynix | SATA II Patched bios (Middleton) | Samsung EVO 850
Arch Linux | Linux 4.3.X x86_64

Link to comment
Share on other sites

Link to post
Share on other sites

I know. Linux is 100% C. But there is my point, Linux took 10 years to develop to become useable and modern enough to support exotic hardware. So took Windows.

C is wasting time imo

It depends on the platform.

C is ligthweigth and ideal for embedded systems and microcontrollers. For a full sized PC you can afford using a comftabe language that needs more resoucese.

Mineral oil and 40 kg aluminium heat sinks are a perfect combination: 73 cores and a Titan X, Twenty Thousand Leagues Under the Oil

Link to comment
Share on other sites

Link to post
Share on other sites

It depends on the platform.

C is ligthweigth and ideal for embedded systems and microcontrollers. For a full sized PC you can afford using a comftabe language that needs more resoucese.

That is my point. Having so powerful PC's, it does not make sense to waste time on C. C is okay for 8MB Flash on a Router, not for a PC.

C++, Java, Python, Ruby etc. are all far superior to C, and they are written, in C.

The mentality: "If i know C i know all the languages." is wrong.

Go write a simple CLI program that displays help when --help is passed and version when --version is passed, and add error handling.

How much time do you need with Python? 

How much time do you need with C?

My time > PC time

If it takes me 2 hours to speed up a program 2 seconds, it is NOT worth it.

Lenovo/IBM ThinkPad T61 Widescreen 15.4" 1680x1050
Intel Core2Duo T8300 2.4GHz | 3GB DDR2 from Hynix | SATA II Patched bios (Middleton) | Samsung EVO 850
Arch Linux | Linux 4.3.X x86_64

Link to comment
Share on other sites

Link to post
Share on other sites

Check how it behaves if ends up being decimical fraction. In some cases user won't be able to type exact mean number, and you program will fail

Using Tapatalk

Link to comment
Share on other sites

Link to post
Share on other sites

-

It may not be worth it to you , but it will be to other people.

Efficiency is key in a lot of applications.

That's why we have broken games nowadays. Because game devs are kinda ignoring it , being pressured into making games faster and faster by the publishers. Just a very simple example which is felt by pretty much all of us these days.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Could we quit arguing availability and usage and actually help OP? 

 

Obviously this is for a class at university. It's beyond his control as to which language he learns inside of his class. If you guys knew as much about languages as you like to assert, then maybe you could help OP?

 

 

 

Comparing for equality with float values could possibly not always give you the correct result (comparison that will be true).

You could compare using epsilon, and you also need to determine how close/precise you would like the results to be.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×