AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
AdjacencyMatrixTest.java
Go to the documentation of this file.
1package aud.test;
2
4
5import org.junit.*;
6import static org.junit.Assert.*;
7
8public class AdjacencyMatrixTest {
9
10 @Test
11 public void testMatrix() {
13 assertFalse(m.isSymmetricMatrix());
14
15 m.set(1,1,1); m.set(1,2,4); m.set(1,3,7);
16 m.set(2,1,2); m.set(2,2,5); m.set(2,3,8);
17 m.set(3,1,3); m.set(3,2,6); m.set(3,3,9);
18
19 assertSame(m.nnz(),9);
20
22
23 assertSame(m.nnz(),4);
24 assertSame(m.get(1,1),1); assertSame(m.get(1,3),7);
25 assertSame(m.get(3,1),3); assertSame(m.get(3,3),9);
26 }
27
28 @Test
29 public void testSymmatrixMatrix() {
31 assertTrue(m.isSymmetricMatrix());
32
33 m.set(1,1,1);
34 m.set(2,1,2); m.set(2,2,4);
35 m.set(3,1,3); m.set(3,2,5); m.set(3,3,6);
36
37 assertSame(m.nnz(),9);
38
40
41 assertSame(m.nnz(),4);
42 assertSame(m.get(1,1),1); assertSame(m.get(1,3),3);
43 assertSame(m.get(3,1),3); assertSame(m.get(3,3),6);
44 }
45
46 public static void main(String args[]) {
47 org.junit.runner.JUnitCore.main("aud.test.AdjacencyMatrixTest");
48 }
49}
Sparse adjacency matrix.
void clearColumnAndRow(int idx)
Set all entries in row idx and column idx to null.
T get(int i, int j)
get entry (i,j) [O(log(nnz))]
int nnz()
get number of nonzero entries
T set(int i, int j, T data)
Set entry (i,j) to data [O(log(nnz))].
boolean isSymmetricMatrix()
Was matrix created explicitly as symmetric matrix?
static void main(String args[])
Graph data structures and algorithms.
AuD lecture: Data structures, algorithms, examples.
Definition: A234Tree.java:1