I'm making a PageRank class that relies on some linear algebra operations that I've written myself. Since I couldn't be bothered to learn JUnit testing, I decided to write my own testing class for my PageRank class. Unfortunately, it wasn't as easy as I expected. Here's my basic idea:
pagerank/PageRankTest.java:
package pagerank;
public class PageRankTester{
public static PageRank pagerank = new PageRank();
public static void main(String[] args){
testNorm();
testSubtract();
testDot();
testMatrixMul();
}
private static void testNorm(){
// Tests pagerank.norm()
}
private static void testSubtract(){
// Tests pagerank.subtract()
}
public static void testDot(){
// Tests pagerank.dot()
}
public static void testMatrixMul(){
// Tests pagerank.matrixMul()
}
}
pagerank/PageRank.java:
package pagerank;
import java.util.*;
import java.io.*;
public class PageRank {
public PageRank( String filename ) {
}
/* --------------------------------------------- */
private double[] dot(double[] x, double[][] P){
//returns dot product between vector and matrix
return res;
}
private double[][] matrixMul(double x, double[][] J){
//returns x*J
return J;
}
private double[] subtract(double[] x, double[] y){
//returns elementwise x-y
return v;
}
private double norm(double[] x){
// returns euclidean norm of x
return norm;
}
public static void main( String[] args ) {
if ( args.length != 1 ) {
System.err.println( "Please give the name of the link file" );
}
else {
new PageRank( args[0] );
}
}
}
This causes a number of issues.
1: When compiling the test class using javac PageRankTester.java
I get the following error:
$ javac PageRankTester.java
PageRankTester.java:4: error: cannot find symbol
public static PageRank pagerank = new PageRank();
^
symbol: class PageRank
location: class PageRankTester
PageRankTester.java:4: error: cannot find symbol
public static PageRank pagerank = new PageRank();
^
symbol: class PageRank
location: class PageRankTester
2 errors
I thought when you put everything in a package you didn't have to import? My only conclusion is that I'm compiling the wrong way because I've worked in packages where I don't need to import anything from another package.
2: Compiling PageRank.java works fine, but when trying to run PageRank using java PageRank
I get:
$ java PageRank
Error: Could not find or load main class PageRank
Caused by: java.lang.NoClassDefFoundError: pagerank/PageRank (wrong name: PageRank)
I've tried java -cp . PageRank
, to prevent this error, but with no success.
What is the proper way to achieve what I want here?