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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steven.liatti
poo2019numeric
Commits
df19a236
Commit
df19a236
authored
5 years ago
by
tanguy.dietrich
Browse files
Options
Downloads
Patches
Plain Diff
Ajout de add, mul, sub, len, et divers test...
parent
2fb9c55d
No related branches found
No related tags found
2 merge requests
!2
Tanguy
,
!1
David
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/numeric/Vector.java
+41
-8
41 additions, 8 deletions
src/main/java/ch/hepia/numeric/Vector.java
src/test/java/ch/hepia/numeric/AppTest.java
+8
-9
8 additions, 9 deletions
src/test/java/ch/hepia/numeric/AppTest.java
with
49 additions
and
17 deletions
src/main/java/ch/hepia/numeric/Vector.java
+
41
−
8
View file @
df19a236
...
@@ -35,10 +35,10 @@ final public class Vector {
...
@@ -35,10 +35,10 @@ final public class Vector {
}
}
public
int
len
()
{
public
int
len
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
//throw new UnsupportedOperationException("This feature isn't implemented yet");
return
this
.
lstVector
.
size
();
}
}
//assertEquals(v1.toString(), "Vector[1.0, 2.0, 3.0]");
//assertEquals(v1.add(v2),v3);
public
double
get
(
int
i
)
{
public
double
get
(
int
i
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
...
@@ -58,11 +58,23 @@ final public class Vector {
...
@@ -58,11 +58,23 @@ final public class Vector {
}
}
public
Vector
mul
(
double
m
)
{
public
Vector
mul
(
double
m
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
//throw new UnsupportedOperationException("This feature isn't implemented yet");
Vector
v
=
new
Vector
();
for
(
int
i
=
0
;
i
<
this
.
lstVector
.
size
();
i
++)
//a ameliorer avec for(e:element)
{
v
.
lstVector
.
add
(
this
.
lstVector
.
get
(
i
)*
m
);
}
return
v
;
}
}
public
Vector
sub
(
Vector
that
)
{
public
Vector
sub
(
Vector
that
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Vector
v
=
new
Vector
();
for
(
int
i
=
0
;
i
<
this
.
lstVector
.
size
();
i
++)
//a ameliorer avec for(e:element)
{
v
.
lstVector
.
add
(
this
.
lstVector
.
get
(
i
)-
that
.
lstVector
.
get
(
i
));
}
return
v
;
//throw new UnsupportedOperationException("This feature isn't implemented yet");
}
}
public
double
norm
()
{
public
double
norm
()
{
...
@@ -116,7 +128,9 @@ final public class Vector {
...
@@ -116,7 +128,9 @@ final public class Vector {
}
}
public
static
Vector
empty
()
{
public
static
Vector
empty
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Vector
v
=
new
Vector
();
return
v
;
//throw new UnsupportedOperationException("This feature isn't implemented yet");
}
}
public
static
Vector
fill
(
int
nb
,
double
value
)
{
public
static
Vector
fill
(
int
nb
,
double
value
)
{
...
@@ -155,7 +169,7 @@ final public class Vector {
...
@@ -155,7 +169,7 @@ final public class Vector {
// Apply formatting to the string if necessary
// Apply formatting to the string if necessary
strings
.
add
(
d
.
toString
());
strings
.
add
(
d
.
toString
());
}
}
if
(
this
instanceof
Vector
)
if
(
this
instanceof
ch
.
hepia
.
numeric
.
Vector
)
{
{
return
"Vector"
+
String
.
valueOf
(
strings
);
return
"Vector"
+
String
.
valueOf
(
strings
);
}
}
...
@@ -166,8 +180,27 @@ final public class Vector {
...
@@ -166,8 +180,27 @@ final public class Vector {
//throw new UnsupportedOperationException("This feature isn't implemented yet");
//throw new UnsupportedOperationException("This feature isn't implemented yet");
}
}
/*
@Override
@Override
public boolean equals(Object obj) {
public boolean equals(Object obj) {
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
if(this instanceof ch.hepia.numeric.Vector)
{
for(int i=0;i<this.lstVector.size();i++)//a ameliorer avec for(e:element)
{
if(((Vector)obj).lstVector.get(i)!=this.lstVector.get(i))
{
return false;
}
}
return true;
}
else
{
//a ecrire
return true;
}
//throw new UnsupportedOperationException("boolean This feature isn't implemented yet");
}
}
*/
}
}
This diff is collapsed.
Click to expand it.
src/test/java/ch/hepia/numeric/AppTest.java
+
8
−
9
View file @
df19a236
...
@@ -15,15 +15,13 @@ class VectorTest {
...
@@ -15,15 +15,13 @@ class VectorTest {
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
);
Vector
v3
=
Vector
.
of
(-
1.0
,
-
2.0
,
-
3.0
);
Vector
v3
=
Vector
.
of
(-
1.0
,
-
2.0
,
-
3.0
);
v3
=
v1
.
add
(
v2
);
//Transposed t1= new Transposed(v2);
System
.
out
.
println
(
v1
.
toString
());
//System.out.println(v1.toString());
System
.
out
.
println
(
v2
.
toString
());
assertEquals
(
v1
.
add
(
v2
).
toString
(),
Vector
.
of
(
0.0
,
0.0
,
0.0
).
toString
());
System
.
out
.
println
(
v3
.
toString
());
assertEquals
(
v1
.
sub
(
v2
).
toString
(),
Vector
.
of
(
2.0
,
4.0
,
6.0
).
toString
());
//assertEquals(v1.add(v2), Vector.of(0.0, 0.0, 0.0));
assertEquals
(
v1
.
mul
(
3.0
).
toString
(),
Vector
.
of
(
3.0
,
6.0
,
9.0
).
toString
());
//assertEquals(v1.sub(v2), Vector.of(2.0, 4.0, 6.0));
assertEquals
(
Vector
.
empty
().
len
(),
0
);
//assertEquals(v1.mul(3.0), Vector.of(3.0, 6.0, 9.0));
assertEquals
(
Vector
.
of
(
1.0
,
2.0
,
1.0
).
len
(),
3
);
//assertEquals(Vector.empty().len(), 0);
//assertEquals(Vector.of(1.0, 2.0, 1.0).len(), 3);
}
}
/*
/*
@Test
@Test
...
@@ -68,6 +66,7 @@ class VectorTest {
...
@@ -68,6 +66,7 @@ class VectorTest {
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]"
);
//System.out.println(v.t().toString());
//assertEquals(v.t().toString(), "Transposed[1.0, 2.0, 3.0]");
//assertEquals(v.t().toString(), "Transposed[1.0, 2.0, 3.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