This document contains 8 exercises related to testing code. Each exercise provides code snippets and asks questions about generating test cases to achieve various coverage criteria like statement coverage, branch coverage, condition coverage, and path coverage. Test cases are needed to cover things like different code blocks, branches, conditions, and paths through the code. Some exercises also ask about identifying test cases that would cause specific code blocks or branches to fail or be executed.
In this chapter we will discuss exceptions in the object-oriented programming and in C# in particular. We will learn how to handle exceptions using the try-catch construct, how to pass them to the calling methods and how to throw standard or our own exceptions using the throw construct. We will give various examples for using exceptions. We will look at the types of exceptions and the exceptions hierarchy in the .NET Framework. At the end, we will look at the advantages of using exceptions, best practices and how to apply them in different situations.
In this chapter we will discuss exceptions in the object-oriented programming and in C# in particular. We will learn how to handle exceptions using the try-catch construct, how to pass them to the calling methods and how to throw standard or our own exceptions using the throw construct. We will give various examples for using exceptions. We will look at the types of exceptions and the exceptions hierarchy in the .NET Framework. At the end, we will look at the advantages of using exceptions, best practices and how to apply them in different situations.
In this chapter we will examine the loop programming constructs through which we can execute a code snippet repeatedly. We will discuss how to implement conditional repetitions (while and do-while loops) and how to work with for-loops. We will give examples of different possibilities to define loops, how to construct them and some of their key usages. Finally, we will discuss the foreach-loop construct and how we can use multiple loops placed inside each other (nested loops).
Programming Fundamentals Arrays and Strings imtiazalijoono
Programming Fundamentals
Arrays and Strings
• Arrays
• Initializing arrays
• Multidimensional arrays
• Arrays as arguments to functions
• Strings
• String functions
Accessing Individual Components
Declaring Arrays
Arrays: Example Garbage
Multidimensional Arrays
1) Write a C program using arrays that produces the multiplication of two 2x2 matrices.
3-Dimensional Array
Write a program of your own choice that makes use of arrays of more than 2 dimensions.
2-Dimensional Arrays
Some practice exercises.
You will certainly have simpler approaches, correct my mistakes and complete the ones I did not finish. Some of the examples where as par my following lessons examples from the books I read, please observe and give all due copyrights to these wonderful authors.
In this chapter we will examine the loop programming constructs through which we can execute a code snippet repeatedly. We will discuss how to implement conditional repetitions (while and do-while loops) and how to work with for-loops. We will give examples of different possibilities to define loops, how to construct them and some of their key usages. Finally, we will discuss the foreach-loop construct and how we can use multiple loops placed inside each other (nested loops).
Programming Fundamentals Arrays and Strings imtiazalijoono
Programming Fundamentals
Arrays and Strings
• Arrays
• Initializing arrays
• Multidimensional arrays
• Arrays as arguments to functions
• Strings
• String functions
Accessing Individual Components
Declaring Arrays
Arrays: Example Garbage
Multidimensional Arrays
1) Write a C program using arrays that produces the multiplication of two 2x2 matrices.
3-Dimensional Array
Write a program of your own choice that makes use of arrays of more than 2 dimensions.
2-Dimensional Arrays
Some practice exercises.
You will certainly have simpler approaches, correct my mistakes and complete the ones I did not finish. Some of the examples where as par my following lessons examples from the books I read, please observe and give all due copyrights to these wonderful authors.
I am Baddie K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
Visual programming (VP) refers to a method of programming that uses a graphical interface to create and modify code, rather than typing out code manually. Unlike traditional text-based programming, visual programming uses visual elements to represent code. Some graphical elements you can use when creating programs with VP include:
This talk is a look into some of the surprising performance cases in Java -- with the goal of illustrating a few simple truths about the nature of compilers.
I am Arnold H. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Sheffield, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++ Programming.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
1. Exercise 1
1. void f() {
2. float x;
3. float y;
4. x = read();
5. y = read();
6. if (x > 0)
7. x += 10;
8. y = y / x;
9. write(x);
10. write(y);
11. }
Create the control flow graph of this program
Write the test cases using the following coverage criteria
Node coverage (statement coverage)
Edge coverage (branch coverage)
Do they identify the fault ?
Note well:
Create one node for each atomic statement
Compound statements must be divided into atomic statements
Create an edge from node N1 to node N2 if during the execution the corresponding statements
can be executed one immediately after the other
1
2. Exercise 2
The following Java function returns the highest absolute value in an array of maximum 5 integers (and
minimum 1), -1 if bad input (too large array, empty array, etc..).
1. public int max_absolute(int[] numbers){
2. if(numbers.length > 5)
3. return -1;
4. int max_value = 0;
5. for(int i = 0; i<numbers.length; i++){
6. if (numbers[i] < 0 )
7. max_value = Math.max(max_value,Math.abs(numbers[i]));
8. else max_value = Math.max(max_value, numbers[i]);
9. }
10. return max_value;
11. }
Draw the control graph;
The function is tested with the following test cases (separately): for each of them, define
statement, branch and loop ratio coverage.
int[] all_equals = {0,0,0,0,0}; // T1 - (0)
int[] all_positive = {1,2,3,4,5}; // T2- (5)
int[] all_negative = {-1,-2,-3,-4,-5}; // T3- (5)
int[] out_of_size = {1,2,3,4,5,6}; // T4- (-1)
int[] mixed = {-10,10,3,5,-6}; // T5 - (10)
int[] empty = {}; // T6 - (-1)
best until now: T5 + T4 (provide 100% node coverage, 100% branch coverage, but
only 1/3 loop)
we need two more test cases to achieve 100% coverage on loop coverage: T6, T7 {1}
LOOP coverage requires T5+T6+T7
T5 {{-10,10,3,5,-6}; Enters in loop 5 times coverage 1/3
T6 {} Enters in loop 0 times coverage 1/3
T4 IS NOT SAME AS T6 for loop coverage
T7 {1} Enters in loop 1 time
Finally we achieve 100% coverage (Statement, branch and loop) with T4, T5, T6, T7
T6 will fail
Which test case will fail?
Which combination of tests can assure 100% coverage of branches, statements and loops ?
2
3. Exercise 3
Assume following specification for some piece of code which could be part of a bisection algorithm to
find π/2:
• Input parameters are the float values a and b.
• Swap a and b unless a <= b.
• Set a and b to 1 and 3 unless cos(a) >= 0 or cos(b) <= 0.
• Set x to the arithmetic mean of a and b.
• Set a to x if cos(x) > 0 and b to x otherwise.
• Print a and b.
This is the code:
1. if (a > b) {
2. float tmp(b); b = a; a = tmp;
3. }
4. if (cos(a) < 0 || cos(b) > 0) {
5. a = 1; b = 3;
6. }
7. x = (a + b) / 2;
8. if (cos(x) > 0) {
9. a = x;
10. } else {
11. b = x;
12. }
Write test cases that are able to cover the following situations:
(A) swap code at line 2
(B) line 2 is not executed
(C) line 5 is executed
(D) line 5 is not executed
(E) line 9 is executed
(F) Line 11 is executed
3
4. Exercise 4
Consider the following requirements and code:
The program shall take as input an array of three integer numbers.
The program shall output the greatest number among the elements of the array.
The program shall order the elements of the array in decreasing order.
1. public int[] order(int v[]) {
2. int tmp;
3. if (v[0]<v[1]) {
4. tmp = v[0];
5. v[1] = v[1];
6. v[1] = tmp;
7. }
8. if (v[1]<v[2]) {
9. tmp = v[0];
10. v[1] = v[2];
11. v[2] = tmp;
12. }
13. return v;
14. }
Create the control flow graph
Write the test cases in order to find the errors, using the following coverage criteria: Node
(statement) coverage, Edge (branch) coverage, Path coverage
4
5. Exercise 5
Consider the following code:
#include <iostream.h>
int main(void) {
int nDependents, Exemption;
float Income, TaxSubTotal, TaxTotal;
cout << "Welcome to the Elbonian tax calculator. Enter your
yearly income: ";
cin >> Income;
// first if - check income
if (Income < 0) {
cout << "You cannot have a negative income.n";
return 0;
}
cout << "Enter the number of dependents you have, including
yourself: ";
cin >> nDependents;
// second if - check dependents
if (nDependents <= 0) {
cout <<"You must have at least one dependent.n";
return 0;
}
// third if (else-if) - compute tax subtotal
if (Income < 10000)
TaxSubTotal = .02 * Income;
else if (Income < 50000)
TaxSubTotal = 200 + .03 * (Income - 10000);
else
TaxSubTotal = 1400 + .04 * (Income - 50000);
Exemption= nDependents * 50;
TaxTotal=TaxSubTotal - Exemption;
5
6. // last if - check negative tax
if (TaxTotal<0) //In case of negative tax
TaxTotal=0;
cout << "$S$S$S$S$S$S$S$S$S$S$S$S$S$S$S$S$S$ n";
cout << "Elbonian Tax Collection Agency n";
cout << "Tax Bill n";
cout << " Citizen's Income: " << Income <<'n';
cout << " Tax Subtotal: " << TaxSubTotal << 'n';
cout << "Number of Dependents: " << nDependents << 'n';
cout << " Tax Exepmtion: " << Exemption << 'n';
cout << " Final Tax Bill: " << TaxTotal << 'n';
cout << "$S$S$S$S$S$S$S$S$S$S$S$S$S$S$S$S$S$ n";
}
Build a test-suite for complete path coverage.
6
7. Exercise 6
Consider the following code:
1. float foo (int a, int b, int c, int d, float e) {
2. float e;
3. if (a == 0) {
4. return 0;
5. }
6. int x = 0;
7. if ((a==b) || ((c == d) && bug(a) )) {
8. x=1;
9. }
10. e = 1/x;
11. return e;
12. }
Function bug(a) should return a value of true when passed a value of a=1.
Build:
• a test suite for 100% statement coverage
• a test suite for 100% branch coverage
• a test suite for 100% condition coverage
7
8. Exercise 7
A function converts a sequence of chars in an integer number. The sequence can start with a ‘-‘ (negative
number). If the sequence is shorter than 6 chars, it is filled with blanks (to the left side).
The integer number must be in the range minint = -32768 to maxint = 32767.
The function signals an error if the sequence of chars is not allowed.
1. public class ConvertInt {
2. public int convert(char[] str) throws Exception{
3. if (str.length > 6)
4. throw new Exception();
5. int number=0;int digit; int i=0;
6. if (str[0]=='-')
7. i=1;
8. for(; i<str.length; i++){
9. digit = str[i] - '0';
10. number = number * 10 + digit;
11. }
12. if (str[0]=='-')
13. number = -number;
14. if (number > 32767 || number < -32768)
number > 32767 T T F F
number < -32768 T F T F
T6 T3 T8 T2
Not “-
feasible 60000”
15. throw new Exception();
16. return number;
17. }
18. }
Write tests in order to achieve:
• node coverage
• edge coverage
• condition coverage for all if statements
• multiple condition coverage of if statement at line 14
• path coverage
Compare the tests cases written here with the ones written with the black box approach. Are they the same or
not?
8
9. Exercise 8
A queue of events in a simulation system receives events. Each event has a time tag.
It is possible to extract events from the queue, the extraction must return the event with lower time tag.
The queue discards events with negative or null time tag.
The queue must accept at least 100.000 events.
Events with the same time tag must be merged (i.e. the second received is discarded)
Define test cases to achieve
• Node coverage
• Edge coverage
1. import java.util.Iterator;
2. import java.util.LinkedList;
3.
4. public class EventsQueue {
5. private LinkedList queue;
6.
7. public EventsQueue(){
8. queue = new LinkedList();
9. }
10. public void insert(int event){
11. int index = 0;
12. int size = queue.size();
13. while (index < size &&
14. ((Integer)queue.get(index)).intValue() < event){
15. index++;
16. }
17. queue.add(index, new Integer(event));
18. }
19. public int pop(){
20. Object o = queue.getFirst();
21. if (o != null)
22. return ((Integer) o).intValue();
23. else return -1;
24. }
25. public void print(){
26. Iterator i = queue.iterator();
27. int event;
28. while (i.hasNext()){
29. event = ((Integer) i.next()).intValue();
30. System.out.println(event + " ");
31. }
32. }}
9