AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
SparseMatrixCSTest.java
Go to the documentation of this file.
1package aud.test;
2
3import aud.Vector;
5
6import org.junit.*;
7import static org.junit.Assert.*;
8
9public class SparseMatrixCSTest {
10
11 @Test
12 public void testMatrix() {
14 assertSame(m.nnz(),0);
15 assertSame(m.getNumRows(),0);
16 assertSame(m.getNumColumns(),0);
17 assertSame(m.getMinRowIndex(),0);
18 assertSame(m.getMinColumnIndex(),0);
19
20 m.set(2,2,2);
21 m.set(9,9,9);
22
23 assertSame(m.getNumRows(),9);
24 assertSame(m.getNumColumns(),9);
25 assertSame(m.getMinRowIndex(),2);
26 assertSame(m.getMinColumnIndex(),2);
27
28 assertSame(m.get(2,2),2);
29 assertSame(m.get(9,9),9);
30 assertSame(m.nnz(),2);
31
32 m.set(2,2,3);
33 assertSame(m.get(2,2),3);
34 assertSame(m.nnz(),2);
35
36 m.set(2,2,null);
37 assertSame(m.get(2,2),null);
38 assertSame(m.nnz(),1);
39
40 m.set(2,2,2);
41
42 m.set(4,2,-1);
43 assertSame(m.get(4,2),-1);
44 assertSame(m.get(2,4),null);
45
46 int[] ri=m.getColumnRowIndices(2);
48
49 assertSame(ri.length,2);
50 assertSame(m.columnDegree(2),2);
51 assertSame(ri[0],2);
52 assertSame(ri[1],4);
53 assertEquals(v.at(0),Integer.valueOf(2));
54 assertEquals(v.at(1),Integer.valueOf(-1));
55
56 assertSame(m.spones().nnz(),m.nnz());
57 }
58
59 public static void main(String args[]) {
60 org.junit.runner.JUnitCore.main("aud.test.SparseMatrixCSTest");
61 }
62}
Implementation of an array-based vector.
Definition: Vector.java:44
T at(int i)
get i-th entry [O(1)]
Definition: Vector.java:92
Simple sparse matrix data structure.
int getMinColumnIndex()
get minimum row index [O(1)]
int getNumRows()
computes from maximium row index [O(nnz)]
int[] getColumnRowIndices(int j)
get row indices in column j as array
T get(int i, int j)
get entry (i,j) [O(log(nnz))]
int getMinRowIndex()
get minimum row index [O(nnz)]
int columnDegree(int j)
get number of nonzero entries in column j
int getNumColumns()
computed from maximum column index [O(1)]
SparseMatrixCS< Integer > spones()
Get nonzero pattern.
T set(int i, int j, T data)
Set entry (i,j) to data [O(log(nnz))].
Vector< T > getColumnEntries(int j)
get entries in column j as array
int nnz()
get number of nonzero entries
static void main(String args[])
sparse matrices for encoding adjacency
Definition: Coordinate.java:1
Graph data structures and algorithms.
AuD lecture: Data structures, algorithms, examples.
Definition: A234Tree.java:1