Skip to content

Commit 02a841e

Browse files
committed
Initial Commit
0 parents  commit 02a841e

28 files changed

+493
-0
lines changed

Diff for: .gitignore

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
.DS_Store
2+
*.ini
3+
4+
## Ignore C++ build and output files
5+
6+
# Prerequisites
7+
*.d
8+
9+
# Compiled Object files
10+
*.slo
11+
*.lo
12+
*.o
13+
*.obj
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Compiled Dynamic libraries
20+
*.so
21+
*.dylib
22+
*.dll
23+
24+
# Fortran module files
25+
*.mod
26+
*.smod
27+
28+
# Compiled Static libraries
29+
*.lai
30+
*.la
31+
*.a
32+
*.lib
33+
34+
# Executables
35+
*.exe
36+
*.out
37+
*.app
38+
39+
40+
## Ignore CMake build files
41+
cmake-build-debug/
42+
43+
44+
## Ignore CLion files
45+
.idea/
46+
*.iml
47+
48+
## Ignore Visual Studio temporary files, build results, and
49+
## files generated by popular Visual Studio add-ons.
50+
##
51+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
52+
53+
# User-specific files
54+
*.rsuser
55+
*.suo
56+
*.user
57+
*.userosscache
58+
*.sln.docstates
59+
60+
# User-specific files (MonoDevelop/Xamarin Studio)
61+
*.userprefs
62+
63+
# Build results
64+
[Dd]ebug/
65+
[Dd]ebugPublic/
66+
[Rr]elease/
67+
[Rr]eleases/
68+
x64/
69+
x86/
70+
bld/
71+
[Bb]in/
72+
[Oo]bj/
73+
[Ll]og/
74+
75+
# Visual Studio 2015/2017 cache/options directory
76+
.vs/
77+
78+
# Visual Studio 2017 auto generated files
79+
Generated\ Files/
80+
81+
# Files built by Visual Studio
82+
*_i.c
83+
*_p.c
84+
*_h.h
85+
*.ilk
86+
*.meta
87+
*.obj
88+
*.iobj
89+
*.pch
90+
*.pdb
91+
*.ipdb
92+
*.pgc
93+
*.pgd
94+
*.rsp
95+
*.sbr
96+
*.tlb
97+
*.tli
98+
*.tlh
99+
*.tmp
100+
*.tmp_proj
101+
*_wpftmp.csproj
102+
*.log
103+
*.vspscc
104+
*.vssscc
105+
.builds
106+
*.pidb
107+
*.svclog
108+
*.scc
109+
110+
# Visual C++ cache files
111+
ipch/
112+
*.aps
113+
*.ncb
114+
*.opendb
115+
*.opensdf
116+
*.sdf
117+
*.cachefile
118+
*.VC.db
119+
*.VC.VC.opendb
120+
121+
# Visual Studio profiler
122+
*.psess
123+
*.vsp
124+
*.vspx
125+
*.sap
126+
127+
# Visual Studio Trace Files
128+
*.e2e
129+
130+
# Visual Studio code coverage results
131+
*.coverage
132+
*.coveragexml
133+
134+
# Visual Studio cache files
135+
# files ending in .cache can be ignored
136+
*.[Cc]ache
137+
# but keep track of directories ending in .cache
138+
!*.[Cc]ache/
139+
140+
# Others
141+
ClientBin/
142+
~$*
143+
*~
144+
*.dbmdl
145+
*.dbproj.schemaview
146+
*.jfm
147+
*.pfx
148+
*.publishsettings
149+
orleans.codegen.cs
150+
151+
# Including strong name files can present a security risk
152+
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
153+
*.snk
154+
155+
# Since there are multiple workflows, uncomment next line to ignore bower_components
156+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
157+
bower_components/
158+
159+
160+
# Backup & report files from converting an old project file
161+
# to a newer Visual Studio version. Backup files are not needed,
162+
# because we have git ;-)
163+
_UpgradeReport_Files/
164+
Backup*/
165+
UpgradeLog*.XML
166+
UpgradeLog*.htm
167+
ServiceFabricBackup/
168+
*.rptproj.bak
169+
170+
# Local History for Visual Studio
171+
.localhistory/

Diff for: .travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
language: cpp
2+
script: cmake . && make && ./check

Diff for: CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.9)
2+
project(Assignment-4)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
6+
add_subdirectory(gtest)
7+
add_subdirectory(problem-1)
8+
add_subdirectory(problem-2)
9+
add_subdirectory(problem-3)
10+
add_subdirectory(problem-4)
11+
add_subdirectory(problem-5)
12+
13+
add_executable(check check.cpp)
14+
target_link_libraries(check gtest problem-1 problem-2 problem-3 problem-4 problem-5)

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Programming Languages Class
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Assignment 4
2+
Solve problems 1-5 by editing the part marked by `// Write your code here` in the **main.cpp** file of each folder.
3+
DO NOT edit any other code or files. DO NOT rename, add, remove, or move any file or folder.
4+
**Any change you make to other files may cause your submission to fail.**
5+
6+
Do not use input/output (cin, cout, or cerr), just use the variable(s) passed to the function as your input,
7+
and assign your output to the return variable.
8+
9+
### Steps:
10+
1. Clone project to your computer
11+
2. Edit **main.cpp** file for each problem with your solution
12+
3. Make sure your code compiles and runs correctly on your IDE
13+
4. Push your code back to this repository (not another repository)
14+
5. Copy repository link to class website as your submission

Diff for: check.cpp

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include <gtest/gtest.h>
2+
3+
#include "problem-1/main.h"
4+
#include "problem-2/main.h"
5+
#include "problem-3/main.h"
6+
#include "problem-4/main.h"
7+
#include "problem-5/main.h"
8+
9+
const int n = 3;
10+
const int m = 3;
11+
int x[n][m] = {{1, 2, 3},
12+
{4, 5, 6},
13+
{7, 8, 9}};
14+
int y[n][m] = {{1, 1, 1},
15+
{2, 2, 2},
16+
{3, 3, 3}};
17+
int z[n][m] = {{14, 14, 14},
18+
{32, 32, 32},
19+
{50, 50, 50}};
20+
21+
22+
int **memcpy(int y[n][m]) {
23+
int **t = new int *[n];
24+
for (int i = 0; i < n; i++) {
25+
t[i] = new int[m];
26+
memcpy(t[i], y[i], sizeof(y[i]));
27+
}
28+
return t;
29+
}
30+
31+
TEST(Problem_1_Test, Transpose_Test) {
32+
int **t = memcpy(y);
33+
int **r = transpose(t, n);
34+
for(int i = 0; i< n; i++) {
35+
for(int j = 0; j< n; j++) {
36+
EXPECT_EQ(r[i][j], t[j][i]);
37+
}
38+
}
39+
}
40+
TEST(Problem_2_Test, Multiply_Test) {
41+
int **t = memcpy(y);
42+
for (int i = 0; i < n; i++) {
43+
int *result = multiply(x[i], t, n);
44+
for (int j = 0; j < m; j++)
45+
EXPECT_EQ(result[j], z[i][j]);
46+
delete[] result;
47+
}
48+
for (int i = 0; i < n; i++) {
49+
delete[] t[i];
50+
}
51+
delete[] t;
52+
}
53+
54+
TEST(Problem_3_Test, Multiply_Test) {
55+
int **t1 = memcpy(x);
56+
int **t2 = memcpy(y);
57+
int **result = multiply(t1, t2, n, m);
58+
for (int i = 0; i < n; i++)
59+
for (int j = 0; j < m; j++) EXPECT_EQ(result[i][j], z[i][j]);
60+
for (int i = 0; i < n; i++) {
61+
delete[] result[i];
62+
delete[] t1[i];
63+
delete[] t2[i];
64+
}
65+
delete[] result;
66+
delete[] t1;
67+
delete[] t2;
68+
}
69+
70+
TEST(Problem_4_Test, MultiplyMatrices_Test) {
71+
int **t1 = memcpy(x);
72+
int **t2 = memcpy(y);
73+
int **result = multiplyMatrices(t1, t2, n, m);
74+
for (int i = 0; i < n; i++)
75+
for (int j = 0; j < m; j++) EXPECT_EQ(result[i][j], z[i][j]);
76+
for (int i = 0; i < n; i++) {
77+
delete[] result[i];
78+
delete[] t1[i];
79+
delete[] t2[i];
80+
}
81+
delete[] result;
82+
delete[] t1;
83+
delete[] t2;
84+
}
85+
86+
TEST(Problem_5_Test, Factorial_Test) {
87+
EXPECT_EQ(factorial(0), 1);
88+
for (int i = 1, f = 1; i < 10; i++, f *= i) {
89+
EXPECT_EQ(factorial(i), f);
90+
}
91+
92+
}
93+
94+
int main(int argc, char **argv) {
95+
::testing::InitGoogleTest(&argc, argv);
96+
return RUN_ALL_TESTS();
97+
}

Diff for: gtest/CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 3.9)
2+
3+
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
4+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
5+
RESULT_VARIABLE result
6+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
7+
if (result)
8+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
9+
endif ()
10+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
11+
RESULT_VARIABLE result
12+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
13+
if (result)
14+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
15+
endif ()
16+
17+
# Prevent overriding the parent project's compiler/linker
18+
# settings on Windows
19+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
20+
21+
# Add googletest directly to our build. This defines
22+
# the gtest and gtest_main targets.
23+
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
24+
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
25+
EXCLUDE_FROM_ALL)

Diff for: gtest/CMakeLists.txt.in

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.9)
2+
3+
project(googletest-download NONE)
4+
5+
include(ExternalProject)
6+
ExternalProject_Add(googletest
7+
GIT_REPOSITORY https://github.com/google/googletest.git
8+
GIT_TAG master
9+
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
10+
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
11+
CONFIGURE_COMMAND ""
12+
BUILD_COMMAND ""
13+
INSTALL_COMMAND ""
14+
TEST_COMMAND ""
15+
)

Diff for: problem-1/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project(problem-1)
2+
add_library(problem-1 main.cpp main.h)

Diff for: problem-1/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Problem 1
2+
Write code to transpose an `nxn` matrix.
3+
4+
Edit the `transpose( )` function in the **main.cpp** file.
5+
The function takes matrix `x` and size `n` as inputs and returns the `result` matrix as the output.
6+
7+
>*Do not write a main function*.
8+
Only edit the part marked with `// Write your code here`

Diff for: problem-1/main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "main.h"
2+
3+
int **transpose(int **y, int n) {
4+
// Write your code here
5+
return 0;
6+
}

0 commit comments

Comments
 (0)