001 // Copyright 2007 Waterken Inc. under the terms of the MIT X license 002 // found at http://www.opensource.org/licenses/mit-license.html 003 package org.waterken.factorial; 004 005 import static org.ref_send.test.Logic.was; 006 007 import org.ref_send.list.List; 008 import org.ref_send.promise.Eventual; 009 import org.ref_send.promise.Promise; 010 011 /** 012 * Eventual invocation tests. 013 */ 014 public final class 015 FactorialN { 016 private FactorialN() {} 017 018 /** 019 * Runs a unit test. 020 * @param _ eventual operator 021 * @param n number to compute factorial of 022 */ 023 static public Promise<?> 024 make(final Eventual _, final int n) { 025 int r = 1; 026 for (int i = n; i > 0; --i) { 027 r *= i; 028 } 029 return _.when(Factorial.make(_, n), was(r)); 030 } 031 032 // Command line interface 033 034 /** 035 * Executes the test. 036 * @param args ignored 037 * @throws Exception test failed 038 */ 039 static public void 040 main(final String[] args) throws Exception { 041 final int n = args.length > 0 ? Integer.parseInt(args[0]) : 4; 042 043 final List<Promise<?>> work = List.list(); 044 final Promise<?> result = make(new Eventual(work.appender()), n); 045 while (!work.isEmpty()) { work.pop().call(); } 046 result.call(); 047 } 048 }