@@ -0,0 +1,2013 @@
+/*%0A * Copyright 2012 Tamas Blummer tamas@bitsofproof.com%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.bitsofproof.supernode.test;%0A%0Aimport static com.bitsofproof.supernode.api.Difficulty.getCompactTarget;%0Aimport static com.bitsofproof.supernode.api.Difficulty.getDifficulty;%0Aimport static com.bitsofproof.supernode.api.Difficulty.getNextTarget;%0Aimport static com.bitsofproof.supernode.api.Difficulty.getTarget;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.math.BigInteger;%0A%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0A%0Aimport com.bitsofproof.supernode.api.ChainParameter;%0Aimport com.bitsofproof.supernode.core.SatoshiChain;%0A%0Apublic class DifficultyTest%0A%7B%0A%09private static ChainParameter chain;%0A%0A%09@BeforeClass%0A%09public static void before ()%0A%09%7B%0A%09%09chain = new SatoshiChain ();%0A%09%7D%0A%0A%09@Test%0A%09public void targetTest ()%0A%09%7B%0A%09%09assertTrue (getTarget (454983370L).toString (16).equals (%221e7eca000000000000000000000000000000000000000000000000%22));%0A%09%7D%0A%0A%09@Test%0A%09public void compactTargetTest ()%0A%09%7B%0A%09%09assertTrue (getCompactTarget (getTarget (454983370L)) == 454983370L);%0A%09%09assertTrue (getCompactTarget (new BigInteger (%22ffff0000000000000000000000000000000000000000000000000000%22, 16)) == 486604799L);%0A%09%7D%0A%0A%09@Test%0A%09public void nextTargetTest ()%0A%09%7B%0A%09%09assertTrue (getNextTarget (841428L, 454983370L, chain) == 454375064L);%0A%09%7D%0A%0A%09@Test%0A%09public void difficultyTest ()%0A%09%7B%0A%09%09assertTrue (getDifficulty (456101533L, chain) == 1378.0);%0A%09%09assertTrue (getDifficulty (486604799L, chain) == 1.0);%0A%09%7D%0A%7D%0A

Test with satoshi chain