Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
poo2019numeric
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steven.liatti
poo2019numeric
Commits
caf65694
Commit
caf65694
authored
5 years ago
by
tanguy.dietrich
Browse files
Options
Downloads
Patches
Plain Diff
ajout du .ToString()
parent
24f76451
No related branches found
No related tags found
2 merge requests
!2
Tanguy
,
!1
David
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/numeric/Vector.java
+17
-10
17 additions, 10 deletions
src/main/java/ch/hepia/numeric/Vector.java
src/test/java/ch/hepia/numeric/AppTest.java
+5
-3
5 additions, 3 deletions
src/test/java/ch/hepia/numeric/AppTest.java
with
22 additions
and
13 deletions
src/main/java/ch/hepia/numeric/Vector.java
+
17
−
10
View file @
caf65694
...
@@ -7,23 +7,24 @@ import java.util.function.Function;
...
@@ -7,23 +7,24 @@ import java.util.function.Function;
final
public
class
Vector
{
final
public
class
Vector
{
private
static
List
<
Double
>
lst
;
// = new ArrayList<Double>();
private
static
List
<
Double
>
lstVector
;
// = new ArrayList<Double>();
private
Vector
()
{
private
Vector
()
{
this
.
lst
=
new
ArrayList
<
Double
>();
this
.
lst
Vector
=
new
ArrayList
<
Double
>();
}
}
private
Vector
(
Double
...
elements
)
{
private
Vector
(
Double
...
elements
)
{
this
.
lst
=
new
ArrayList
<
Double
>();
this
.
lst
Vector
=
new
ArrayList
<
Double
>();
for
(
double
e:
elements
)
for
(
double
e:
elements
)
{
{
lst
.
add
(
e
);
lst
Vector
.
add
(
e
);
}
}
//throw new UnsupportedOperationException("This feature isn't implemented yet");
//throw new UnsupportedOperationException("This feature isn't implemented yet");
}
}
private
Vector
(
List
<
Double
>
elements
)
{
private
Vector
(
List
<
Double
>
elements
)
{
this
.
lst
=
new
ArrayList
<
Double
>();
this
.
lst
Vector
=
new
ArrayList
<
Double
>();
for
(
double
e:
elements
)
for
(
double
e:
elements
)
{
{
lst
.
add
(
e
);
lst
Vector
.
add
(
e
);
}
}
//throw new UnsupportedOperationException("This feature isn't implemented yet");
//throw new UnsupportedOperationException("This feature isn't implemented yet");
}
}
...
@@ -45,9 +46,9 @@ final public class Vector {
...
@@ -45,9 +46,9 @@ final public class Vector {
public
Vector
add
(
Vector
that
)
{
public
Vector
add
(
Vector
that
)
{
//throw new UnsupportedOperationException("This feature isn't implemented yet");
//throw new UnsupportedOperationException("This feature isn't implemented yet");
for
(
double
e:
that
.
lst
)
for
(
double
e:
that
.
lst
Vector
)
{
{
this
.
lst
.
add
(
e
);
this
.
lst
Vector
.
add
(
e
);
}
}
return
this
;
return
this
;
}
}
...
@@ -100,7 +101,7 @@ final public class Vector {
...
@@ -100,7 +101,7 @@ final public class Vector {
Vector
v
=
new
Vector
();
Vector
v
=
new
Vector
();
for
(
double
e:
elements
)
for
(
double
e:
elements
)
{
{
v
.
lst
.
add
(
e
);
v
.
lst
Vector
.
add
(
e
);
}
}
return
v
;
return
v
;
//throw new UnsupportedOperationException("This feature isn't implemented yet");
//throw new UnsupportedOperationException("This feature isn't implemented yet");
...
@@ -145,7 +146,13 @@ final public class Vector {
...
@@ -145,7 +146,13 @@ final public class Vector {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
List
<
String
>
strings
=
new
ArrayList
<
String
>();
for
(
Double
d
:
this
.
lstVector
)
{
// Apply formatting to the string if necessary
strings
.
add
(
d
.
toString
());
}
return
"Vector"
+
String
.
valueOf
(
strings
);
//throw new UnsupportedOperationException("This feature isn't implemented yet");
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
src/test/java/ch/hepia/numeric/AppTest.java
+
5
−
3
View file @
caf65694
...
@@ -14,6 +14,8 @@ class VectorTest {
...
@@ -14,6 +14,8 @@ class VectorTest {
void
vectorMainOperations
()
{
void
vectorMainOperations
()
{
Vector
v1
=
Vector
.
of
(
1.0
,
2.0
,
3.0
);
Vector
v1
=
Vector
.
of
(
1.0
,
2.0
,
3.0
);
Vector
v2
=
Vector
.
of
(-
1.0
,
-
2.0
,
-
3.0
);
Vector
v2
=
Vector
.
of
(-
1.0
,
-
2.0
,
-
3.0
);
//System.out.println(v2.toString());
//v2 = v1.add(v2);
//assertEquals(v1.add(v2), Vector.of(0.0, 0.0, 0.0));
//assertEquals(v1.add(v2), Vector.of(0.0, 0.0, 0.0));
//assertEquals(v1.sub(v2), Vector.of(2.0, 4.0, 6.0));
//assertEquals(v1.sub(v2), Vector.of(2.0, 4.0, 6.0));
//assertEquals(v1.mul(3.0), Vector.of(3.0, 6.0, 9.0));
//assertEquals(v1.mul(3.0), Vector.of(3.0, 6.0, 9.0));
...
@@ -58,14 +60,14 @@ class VectorTest {
...
@@ -58,14 +60,14 @@ class VectorTest {
assertEquals( v3.t().dot(v4), 14.0 );
assertEquals( v3.t().dot(v4), 14.0 );
assertEquals( v3.t().sub(v4.t()), Vector.of(0.0, 0.0, 0.0).t() );
assertEquals( v3.t().sub(v4.t()), Vector.of(0.0, 0.0, 0.0).t() );
}
}
*/
@Test
@Test
void
vectorToString
()
{
void
vectorToString
()
{
Vector
v
=
Vector
.
of
(
1.0
,
2.0
,
3.0
);
Vector
v
=
Vector
.
of
(
1.0
,
2.0
,
3.0
);
assertEquals
(
v
.
toString
(),
"Vector[1.0, 2.0, 3.0]"
);
assertEquals
(
v
.
toString
(),
"Vector[1.0, 2.0, 3.0]"
);
assertEquals(v.t().toString(), "Transposed[1.0, 2.0, 3.0]");
//
assertEquals(v.t().toString(), "Transposed[1.0, 2.0, 3.0]");
}
}
/*
@Test
@Test
void vectorSlice() {
void vectorSlice() {
Vector v = Vector.of(1.0, 2.0, 3.0, 4.0, 5.0);
Vector v = Vector.of(1.0, 2.0, 3.0, 4.0, 5.0);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment