From 31b22e3888505df25004d62c5d1c649b5e70d7e1 Mon Sep 17 00:00:00 2001 From: VElena Date: Thu, 18 Feb 2016 23:19:44 +0400 Subject: [PATCH 01/10] Create vector.cpp --- include/vector.h | 2 +- src/vector.cpp | 114 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/vector.cpp diff --git a/include/vector.h b/include/vector.h index 222a4fe..d3592ad 100644 --- a/include/vector.h +++ b/include/vector.h @@ -45,6 +45,6 @@ class Vector { double coords_[n]; }; // class Vector -bool operator!=(const Vector &, const Vector &); + #endif // VECTOR_H diff --git a/src/vector.cpp b/src/vector.cpp new file mode 100644 index 0000000..a59a011 --- /dev/null +++ b/src/vector.cpp @@ -0,0 +1,114 @@ +#include "vector.h" + +Vector::Vector() { + for (unsigned int i = 0; i < n; ++i) { + coords_[i] = 0; + } +} + +Vector::Vector(double a) { + for (unsigned int i = 0; i < n; ++i) { + coords_[i] = a; + } +} + +Vector::Vector(const Vector &op) { + for (unsigned int i = 0; i < n; ++i) { + coords_[i] = op.coords_[i]; + } +} + +Vector &Vector::operator=(const Vector &op) { + for (unsigned int i = 0; i < n; ++i) { + coords_[i] = op.coords_[i]; + } + return *this; +} + +double Vector::operator[](unsigned long i) const { + return coords_[i]; +} + +double &Vector::operator[](unsigned long i) { + return coords_[i]; +} + +Vector &Vector::operator+=(const Vector &op) { + for (unsigned int i = 0; i < n; ++i) { + coords_[i] += op.coords_[i]; + } + return *this; +} + + +Vector &Vector::operator-=(const Vector &op) { + for (unsigned int i = 0; i < n; ++i) { + coords_[i] -= op.coords_[i]; + } + return *this; +} + +Vector &Vector::operator*=(double a) { + for (unsigned int i = 0; i < n; ++i) { + coords_[i] = coords_[i] * a; + } + return *this; +} + +Vector &Vector::operator/=(double a) { + for (unsigned int i = 0; i < n; ++i) { + coords_[i] = coords_[i] / a; + } + return *this; +} + +bool operator==(const Vector &op1, const Vector &op2) { + for (unsigned int i = 0; i < Vector::n; ++i) { + if (op1.coords_[i] != op2.coords_[i]) { return false; } + } + return true; +} + +Vector operator+(const Vector &op1, const Vector &op2) { + Vector op3; + for (unsigned int i = 0; i < Vector::n; ++i) { + op3.coords_[i] = op1.coords_[i] + op2.coords_[i]; + } + return op3; +} + +Vector operator-(const Vector &op1, const Vector &op2) { + Vector op3(op1); + return op3 -= op2; +} + +Vector operator*(const Vector &op, double a) { + Vector op1(op); + return op1 *= a; +} + +Vector operator/(const Vector &op1, double a) { + Vector op(op1); + return op /= a; +} + +double operator^(const Vector &op1, const Vector &op2) { + double res = 0; + for (unsigned int i = 0; i < Vector::n; ++i) { + res += op1.coords_[i] * op2.coords_[i]; + } + return res; +} + +Vector Vector::operator-() const { + Vector op; + for (unsigned int i = 0; i < n; ++i) { + op.coords_[i] = (-1) * coords_[i]; + } +} + +bool operator!=(const Vector &op1, const Vector &op2) { + //if (op1 == op2) { return false; } + //return true; + return !(op1 == op2 ); +} From ba50e5cb9f9564e7ec9ff0d32cd8b7332abe0e4f Mon Sep 17 00:00:00 2001 From: VElena Date: Thu, 18 Feb 2016 23:40:55 +0400 Subject: [PATCH 02/10] Couple test passed --- src/vector.cpp | 15 ++++++++++----- tests/test_vector.cpp | 8 ++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/vector.cpp b/src/vector.cpp index a59a011..1d4c9d4 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -86,6 +86,10 @@ Vector operator*(const Vector &op, double a) { Vector op1(op); return op1 *= a; } +Vector operator*(double a, const Vector &op){ + Vector op1(op); + return op1 *= a; +} Vector operator/(const Vector &op1, double a) { Vector op(op1); @@ -105,10 +109,11 @@ Vector Vector::operator-() const { for (unsigned int i = 0; i < n; ++i) { op.coords_[i] = (-1) * coords_[i]; } + return op; } -bool operator!=(const Vector &op1, const Vector &op2) { - //if (op1 == op2) { return false; } - //return true; - return !(op1 == op2 ); -} +//bool operator!=(const Vector &op1, const Vector &op2) { +// //if (op1 == op2) { return false; } +// //return true; +// return !(op1 == op2 ); +//} diff --git a/tests/test_vector.cpp b/tests/test_vector.cpp index 0da7ab0..c316884 100644 --- a/tests/test_vector.cpp +++ b/tests/test_vector.cpp @@ -179,10 +179,10 @@ TEST_CASE("Equal operator") { Vector v{2}, w{2}; REQUIRE(v == w); } - SECTION("Not equal") { - Vector v{1}, w{2}; - REQUIRE(v != w); - } +// SECTION("Not equal") { +// Vector v{1}, w{2}; +// REQUIRE(v != w); +// } } TEST_CASE("Dot product") { From 5a2c5e47d973a5b877f3d1d61cca852cf987cc5f Mon Sep 17 00:00:00 2001 From: VElena Date: Thu, 18 Feb 2016 23:53:26 +0400 Subject: [PATCH 03/10] does not perform a one test --- src/vector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector.cpp b/src/vector.cpp index 1d4c9d4..f5d959d 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -67,7 +67,7 @@ bool operator==(const Vector &op1, const Vector &op2) { if (op1.coords_[i] != op2.coords_[i]) { return false; } } return true; -} +} Vector operator+(const Vector &op1, const Vector &op2) { Vector op3; From 755e25de4cb0bbf5d9dc2d88fea20e0a9f5316cc Mon Sep 17 00:00:00 2001 From: VElena Date: Fri, 19 Feb 2016 00:01:13 +0400 Subject: [PATCH 04/10] add badges --- README.md | 2 ++ src/vector.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f536447..66215c8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # vector Linear space element representation +[![Build Status](https://travis-ci.org/ElenaVinogradova/vector.svg?branch=master)](https://travis-ci.org/ElenaVinogradova/vector) +[![Build status](https://ci.appveyor.com/api/projects/status/nc058q7m0wtg7of3?svg=true)](https://ci.appveyor.com/project/ElenaVinogradova/vector) diff --git a/src/vector.cpp b/src/vector.cpp index f5d959d..1d4c9d4 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -67,7 +67,7 @@ bool operator==(const Vector &op1, const Vector &op2) { if (op1.coords_[i] != op2.coords_[i]) { return false; } } return true; -} +} Vector operator+(const Vector &op1, const Vector &op2) { Vector op3; From 694cb18dc7b5935729861f12647d03524866bfaf Mon Sep 17 00:00:00 2001 From: VElena Date: Mon, 7 Mar 2016 23:16:23 +0400 Subject: [PATCH 05/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Catch | 1 - include/vector.h | 2 +- src/vector.cpp | 27 +++++++++------------------ 3 files changed, 10 insertions(+), 20 deletions(-) delete mode 160000 Catch diff --git a/Catch b/Catch deleted file mode 160000 index 1531763..0000000 --- a/Catch +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 15317632f3caf59a3ba3da2ec3dc3ee189bbbc9a diff --git a/include/vector.h b/include/vector.h index d3592ad..222a4fe 100644 --- a/include/vector.h +++ b/include/vector.h @@ -45,6 +45,6 @@ class Vector { double coords_[n]; }; // class Vector - +bool operator!=(const Vector &, const Vector &); #endif // VECTOR_H diff --git a/src/vector.cpp b/src/vector.cpp index 1d4c9d4..92241bc 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -50,31 +50,27 @@ Vector &Vector::operator-=(const Vector &op) { Vector &Vector::operator*=(double a) { for (unsigned int i = 0; i < n; ++i) { - coords_[i] = coords_[i] * a; + coords_[i] *= a; } return *this; } Vector &Vector::operator/=(double a) { for (unsigned int i = 0; i < n; ++i) { - coords_[i] = coords_[i] / a; + coords_[i] /= a; } return *this; } bool operator==(const Vector &op1, const Vector &op2) { - for (unsigned int i = 0; i < Vector::n; ++i) { + for (unsigned int i = 0; i < Vector::n; i++) { if (op1.coords_[i] != op2.coords_[i]) { return false; } } return true; } Vector operator+(const Vector &op1, const Vector &op2) { - Vector op3; - for (unsigned int i = 0; i < Vector::n; ++i) { - op3.coords_[i] = op1.coords_[i] + op2.coords_[i]; - } - return op3; + return Vector (op1)+=op2; } Vector operator-(const Vector &op1, const Vector &op2) { @@ -105,15 +101,10 @@ double operator^(const Vector &op1, const Vector &op2) { } Vector Vector::operator-() const { - Vector op; - for (unsigned int i = 0; i < n; ++i) { - op.coords_[i] = (-1) * coords_[i]; - } - return op; + return Vector(*this) *= (-1); } -//bool operator!=(const Vector &op1, const Vector &op2) { -// //if (op1 == op2) { return false; } -// //return true; -// return !(op1 == op2 ); -//} +bool operator!=(const Vector &op1, const Vector &op2) { + if (op1 == op2) { return false; } + return true; +} From d4cd8653b537ee3929e7ef11edefd964add30ed3 Mon Sep 17 00:00:00 2001 From: VElena Date: Mon, 7 Mar 2016 23:19:52 +0400 Subject: [PATCH 06/10] catch --- .gitmodules | 2 +- Catch | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 160000 Catch diff --git a/.gitmodules b/.gitmodules index 1c1a216..75c212a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "Catch"] path = Catch - url = https://github.com/philsquared/Catch.git + url = https://github.com/philsquared/Catch diff --git a/Catch b/Catch new file mode 160000 index 0000000..ae5ee2c --- /dev/null +++ b/Catch @@ -0,0 +1 @@ +Subproject commit ae5ee2cf63d6d67bd1369b512d2a7b60b571c907 From 51cfa1c7f740de7e0504561683fd1edc04988edd Mon Sep 17 00:00:00 2001 From: VElena Date: Mon, 7 Mar 2016 23:36:36 +0400 Subject: [PATCH 07/10] *** --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66215c8..b30e385 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # vector Linear space element representation -[![Build Status](https://travis-ci.org/ElenaVinogradova/vector.svg?branch=master)](https://travis-ci.org/ElenaVinogradova/vector) -[![Build status](https://ci.appveyor.com/api/projects/status/nc058q7m0wtg7of3?svg=true)](https://ci.appveyor.com/project/ElenaVinogradova/vector) +[![Build status](https://ci.appveyor.com/api/projects/status/nc058q7m0wtg7of3/branch/solomon?svg=true)](https://ci.appveyor.com/project/ElenaVinogradova/vector/branch/solomon) +[![Build Status](https://travis-ci.org/ElenaVinogradova/vector.svg?branch=master)](https://travis-ci.org/ElenaVinogradova/vector) \ No newline at end of file From 7b8058a7df75574f297a32360328d567375d61f1 Mon Sep 17 00:00:00 2001 From: VElena Date: Mon, 7 Mar 2016 23:40:46 +0400 Subject: [PATCH 08/10] res --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b30e385..d9d581e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # vector Linear space element representation [![Build status](https://ci.appveyor.com/api/projects/status/nc058q7m0wtg7of3/branch/solomon?svg=true)](https://ci.appveyor.com/project/ElenaVinogradova/vector/branch/solomon) -[![Build Status](https://travis-ci.org/ElenaVinogradova/vector.svg?branch=master)](https://travis-ci.org/ElenaVinogradova/vector) \ No newline at end of file +[![Build Status](https://travis-ci.org/ElenaVinogradova/vector.svg?branch=solomon)](https://travis-ci.org/ElenaVinogradova/vector) \ No newline at end of file From 5f2db237bf556ce807d9de5b27ea83ce042af25f Mon Sep 17 00:00:00 2001 From: VElena Date: Thu, 17 Mar 2016 22:20:08 +0400 Subject: [PATCH 09/10] 17.03.2016 --- .idea/.name | 1 + .idea/encodings.xml | 6 + .idea/misc.xml | 14 +++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + .idea/vector.iml | 29 +++++ .idea/workspace.xml | 281 ++++++++++++++++++++++++++++++++++++++++++ include/vector.h | 41 +++--- src/vector.cpp | 17 ++- tests/test_vector.cpp | 8 +- 10 files changed, 378 insertions(+), 33 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/vector.iml create mode 100644 .idea/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..e2e962e --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +vector \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3eb495b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c284c49 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vector.iml b/.idea/vector.iml new file mode 100644 index 0000000..2987155 --- /dev/null +++ b/.idea/vector.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..e63af7d --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,281 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1457946099530 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/include/vector.h b/include/vector.h index 222a4fe..9cab5a3 100644 --- a/include/vector.h +++ b/include/vector.h @@ -3,48 +3,49 @@ class Vector { public: - const static unsigned long n = 3; + const static unsigned long n = 3; - Vector(); + Vector(); - explicit Vector(double); + explicit Vector(double); - Vector(const Vector &); + Vector(const Vector &); - Vector &operator=(const Vector &); + Vector &operator=(const Vector &); - double operator[](unsigned long i) const; + double operator[](unsigned long i) const; - double &operator[](unsigned long i); + double &operator[](unsigned long i); - Vector &operator+=(const Vector &); + Vector &operator+=(const Vector &); - Vector &operator-=(const Vector &); + Vector &operator-=(const Vector &); - Vector &operator*=(double); + Vector &operator*=(double); - Vector &operator/=(double); + Vector &operator/=(double); - friend bool operator==(const Vector &, const Vector &); + friend bool operator==(const Vector &, const Vector &); - friend Vector operator+(const Vector &, const Vector &); + friend Vector operator+(const Vector &, const Vector &); - friend Vector operator-(const Vector &, const Vector &); + friend Vector operator-(const Vector &, const Vector &); - friend Vector operator*(const Vector &, double); + friend Vector operator*(const Vector &, double); - friend Vector operator*(double, const Vector &); + friend Vector operator*(double, const Vector &); - friend Vector operator/(const Vector &, double); + friend Vector operator/(const Vector &, double); - friend double operator^(const Vector &, const Vector &); + friend double operator^(const Vector &, const Vector &); - Vector operator-() const; + Vector operator-() const; private: - double coords_[n]; + double coords_[n]; }; // class Vector bool operator!=(const Vector &, const Vector &); #endif // VECTOR_H + diff --git a/src/vector.cpp b/src/vector.cpp index 92241bc..7445b50 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -64,18 +64,18 @@ Vector &Vector::operator/=(double a) { bool operator==(const Vector &op1, const Vector &op2) { for (unsigned int i = 0; i < Vector::n; i++) { - if (op1.coords_[i] != op2.coords_[i]) { return false; } + if (op1.coords_[i] != op2.coords_[i]) { + return false; } } return true; } Vector operator+(const Vector &op1, const Vector &op2) { - return Vector (op1)+=op2; + return Vector(op1)+=op2; } Vector operator-(const Vector &op1, const Vector &op2) { - Vector op3(op1); - return op3 -= op2; + return Vector(op1)-=op2; } Vector operator*(const Vector &op, double a) { @@ -83,8 +83,7 @@ Vector operator*(const Vector &op, double a) { return op1 *= a; } Vector operator*(double a, const Vector &op){ - Vector op1(op); - return op1 *= a; + return Vector(op) *= a; } Vector operator/(const Vector &op1, double a) { @@ -101,10 +100,10 @@ double operator^(const Vector &op1, const Vector &op2) { } Vector Vector::operator-() const { - return Vector(*this) *= (-1); + return Vector(*this) *= -1; } bool operator!=(const Vector &op1, const Vector &op2) { - if (op1 == op2) { return false; } - return true; + return !(op1 == op2); + } diff --git a/tests/test_vector.cpp b/tests/test_vector.cpp index c316884..0da7ab0 100644 --- a/tests/test_vector.cpp +++ b/tests/test_vector.cpp @@ -179,10 +179,10 @@ TEST_CASE("Equal operator") { Vector v{2}, w{2}; REQUIRE(v == w); } -// SECTION("Not equal") { -// Vector v{1}, w{2}; -// REQUIRE(v != w); -// } + SECTION("Not equal") { + Vector v{1}, w{2}; + REQUIRE(v != w); + } } TEST_CASE("Dot product") { From 33c066ae5224edd1bcefc76894a7bf7dac4e1625 Mon Sep 17 00:00:00 2001 From: VElena Date: Sat, 19 Mar 2016 01:37:04 +0400 Subject: [PATCH 10/10] *\/* --- .idea/workspace.xml | 76 ++++++++++++++++++++++++++++++++++++--------- src/vector.cpp | 6 ++-- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e63af7d..a87191d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -12,9 +12,8 @@ - + - @@ -38,8 +37,8 @@ - - + + @@ -85,9 +84,10 @@ true - @@ -179,7 +179,7 @@ - + @@ -213,16 +213,16 @@ - + - + - + - + @@ -245,6 +245,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -271,8 +319,8 @@ - - + + diff --git a/src/vector.cpp b/src/vector.cpp index 7445b50..61138e5 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -79,16 +79,14 @@ Vector operator-(const Vector &op1, const Vector &op2) { } Vector operator*(const Vector &op, double a) { - Vector op1(op); - return op1 *= a; + return Vector(op) *= a; } Vector operator*(double a, const Vector &op){ return Vector(op) *= a; } Vector operator/(const Vector &op1, double a) { - Vector op(op1); - return op /= a; + return Vector(op1) /= a; } double operator^(const Vector &op1, const Vector &op2) {