Commit dd6cea19 authored by Bradon Ladd's avatar Bradon Ladd

Merge branch 'laddbr/lab4' into 'master'

Laddbr/lab4 into Master

See merge request !4
parents 49606100 fcf097f8
Pipeline #20852 passed with stages
in 2 minutes and 43 seconds
##I've written my own comments for reference
image:
gitlab.cs.wallawalla.edu:5050/cptr245/student245
default:
tags:
- shell
- docker
##Before anything is done, move to the area directory, and execute the build script
before_script:
- cd area
after_script:
- echo "After script section"
- echo "For example you might do some cleanup here"
build1:
build program:
stage: build
script:
- g++ -o area areaFunction.cpp areaFunction.h areaMain.cpp
......@@ -20,6 +19,47 @@ build1:
paths:
- area/area
build test:
stage: build
script:
- g++ -o test areaFunction.cpp areaFunction.h areaTest.cpp
artifacts:
paths:
- area/test
format:
stage: build
script:
- |
find . -type f \( -name "*.cpp" -or -name "*.h" \) -exec \
clang-format --dry-run --ferror-limit=1 {} + 2> errFile
err=$(<errFile)
if [[ ! -z "$err" ]]; then
echo "Detected formatting issues; please fix"
cat errFile
exit 1
fi
exit 0
allow_failure: true
cppcheck:
stage: build
script:
- |
find . \( -name \*.h -o -name \*.cpp \) -exec \
cppcheck --language=c++ --enable=all --inconclusive --error-exitcode=1 \
{} +
allow_failure: true
cpplint:
stage: build
script:
- |
find . \( -name \*.h -o -name \*.cpp \) -exec \
cpplint --filter=-legal/copyright \
{} +
allow_failure: true
test1:
stage: test
script:
......@@ -30,7 +70,13 @@ test2:
script:
./area 5
deploy1:
stage: deploy
test text diff:
stage: test
script:
- ./area 3 > stdout.txt && diff stdout.txt area3.txt
- ./area 5 > stdout.txt && diff stdout.txt area5.txt
test function result:
stage: test
script:
- echo "Do your deploy here"
- ./test
\ No newline at end of file
The area of a square with sides of 3 units is 9 units.
The area of a circle with a radius of 3 units is 28.26 units.
The area of a square with sides of 5 units is 25 units.
The area of a circle with a radius of 5 units is 78.5 units.
//Bradon Ladd
//Professor Foster
//CPTR 245
//Lab 01: Testing a Function
// areaFunction.cpp. Contains the implementation of areaOfSquareWithSides prototyped in areaFunction.h
#ifndef AREA_AREAFUNCTION_H_
#define AREA_AREAFUNCTION_H_
#include "areaFunction.h"
float areaOfSquareWithSides(float side){
return side*side;
float areaOfSquareWithSides(float side) { return side * side; }
float areaOfCircleWithRadius(float radius) {
return (3.14 * (radius * radius));
}
float areaOfCircleWithRadius(float radius){
return (3.14 * (radius * radius));
}
\ No newline at end of file
#endif // AREA_AREAFUNCTION_H_
//Bradon Ladd
//Professor Foster
//CPTR 245
//Lab 01: Testing a Function
// areaFunction.h. Prototypes the funciton areaOfSquareWithSides implemented in areaFunction.cpp
#ifndef AREA_AREAFUNCTION_H_
#define AREA_AREAFUNCTION_H_
float areaOfSquareWithSides(float side);
float areaOfCircleWithRadius(float radius);
\ No newline at end of file
float areaOfCircleWithRadius(float radius);
#endif // AREA_AREAFUNCTION_H_
//Bradon Ladd
//Professor Foster
//CPTR 245
//Lab 01: Testing a Function
//areaMain.cpp. Takes in a command line argument that specifies a side of a square and returns the value of the area of a square.
// Checks that there are enough arguments to satisfy the program, then converts the second argument to an integer and runs the function
#include <iostream>
#include "areaFunction.h"
using namespace std;
int main(int argc, char *argv[]){
#include <iostream>
if (argc < 2){
cout << "You must provide at least two arguments in the form of \"./area %d\"" << endl;
return 1;
}
else{
//"atoi()" is C++'s method of converting a string to an integer
float argument = atof(argv[1]);
if (argument == 0){
cout << "Value must be an integer above 0" << endl;
return 1;
}
float squareArea = areaOfSquareWithSides(argument);
float circleArea = areaOfCircleWithRadius(argument);
cout << "The area of a square with sides of " << argv[1] << " units is " << squareArea << " units." << endl;
cout << "The area of a circle with a radius of " << argv[1] << " units is " << circleArea << " units." << endl;
return 0;
int main(int argc, char *argv[]) {
if (argc < 2) {
std::cout
<< "You must provide at least two arguments in the form of \"./area "
"%d\""
<< std::endl;
return 1;
} else {
// "atoi()" is C++'s method of converting a string to an integer
float argument = atof(argv[1]);
if (argument == 0) {
std::cout << "Value must be an integer above 0" << std::endl;
return 1;
}
};
\ No newline at end of file
float squareArea = areaOfSquareWithSides(argument);
float circleArea = areaOfCircleWithRadius(argument);
std::cout << "The area of a square with sides of " << argv[1]
<< " units is " << squareArea << " units." << std::endl;
std::cout << "The area of a circle with a radius of " << argv[1]
<< " units is " << circleArea << " units." << std::endl;
return 0;
}
}
//Bradon Ladd
//Professor Foster
//CPTR 245
//Lab 01: Testing a Function
//areaTest.cpp. Contains the testing done to the areaOfSquareWithSides function implemented in areaFunction.cpp
#include "areaFunction.h"
#include <iostream>
#include <vector>
#include "areaFunction.h"
using namespace std;
int main(){
bool testPasses = true;
//This string logs which tests fail, and is for debugging purposes. A more sophisticated system will come later
string testsFailed = "";
/*Test 1*/
if (areaOfSquareWithSides(3) != 9){
testsFailed += "1 ";
testPasses = false;
}
/*Test 2*/
if (areaOfSquareWithSides(5) != 25){
testsFailed += "2 ";
testPasses = false;
}
/*Test 3*/
if (areaOfSquareWithSides(4) != 16){
testsFailed += "3 ";
testPasses = false;
}
//Test 4 - Circle
//"float a" exists to force a type conversion in the comparisons. Test were
//failing when the secondary value's type was not declared, as the function
//was spitting out a float and trying to compare to a default double in the tests.
float a = 153.86;
if (areaOfCircleWithRadius(7) != a){
cout << areaOfCircleWithRadius(7) << endl;
testsFailed += "4 ";
testPasses = false;
}
//Test 5 - Circle
a = 3.7994;
if (areaOfCircleWithRadius(1.1) != a){
cout << areaOfCircleWithRadius(1.1) << endl;
testsFailed += "5 ";
testPasses = false;
}
/*Confirmation*/
if (testPasses) {
cout << "Test succeeded" << endl;
return 0;
} else {
cout << "Tests Failed: " << testsFailed << endl;
return 1;
}
}
\ No newline at end of file
int main() {
bool testPasses = true;
// This string logs which tests fail, and is for debugging purposes. A more
// sophisticated system will come later
std::string testsFailed = "";
/*Test 1*/
if (areaOfSquareWithSides(3) != 9) {
testsFailed += "1 ";
testPasses = false;
}
/*Test 2*/
if (areaOfSquareWithSides(5) != 25) {
testsFailed += "2 ";
testPasses = false;
}
/*Test 3*/
if (areaOfSquareWithSides(4) != 16) {
testsFailed += "3 ";
testPasses = false;
}
// Test 4 - Circle
// "float a" exists to force a type conversion in the comparisons. Test were
// failing when the secondary value's type was not declared, as the function
// was spitting out a float and trying to compare to a default double in the
// tests.
float a = 153.86;
if (areaOfCircleWithRadius(7) != a) {
testsFailed += "4 ";
testPasses = false;
}
// Test 5 - Circle
a = 3.7994;
if (areaOfCircleWithRadius(1.1) != a) {
testsFailed += "5 ";
testPasses = false;
}
/*Confirmation*/
if (testPasses) {
std::cout << "Test succeeded" << std::endl;
return 0;
} else {
std::cout << "Tests Failed: " << testsFailed << std::endl;
return 1;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment