001package models; 002 003import static org.junit.Assert.*; 004 005import org.junit.Test; 006 007 008/** 009 * Unit tests for the ProductModel class. 010 * 011 * This compares the consistency of the {@link ProductModel} implementation with special cases 012 * that are implemented in other classes as well, for example the classes 013 * {@link IsingModel} and {@link SinhGordonModel}. 014 * 015 */ 016public class ProductModelTest { 017 018 private void compareModels(String msg, IntegrableModel model1, IntegrableModel model2) { 019 compareModels(msg, new IntegrableModel[] {model1}, 0, model2 ); 020 } 021 022 private void compareModels(String msg, IntegrableModel[] expModels, int coshPower, IntegrableModel model2) { 023 024 for (double t = 0.0; t < 10.1; t++) { 025 double expected = 1.0; 026 for (IntegrableModel mod : expModels) { 027 expected *= mod.FminIpi(t); 028 } 029 if (coshPower != 0) { 030 expected *= Math.pow(Math.cosh(t/2), coshPower); 031 } 032 double actual = model2.FminIpi(t); 033 assertEquals(msg + ", t="+t, expected, actual, 1e-3); 034 } 035 036 } 037 038 039 /** 040 * Verifies the product model against the sinh-Gordon model with various couplings. 041 */ 042 @Test 043 public void comparisonWithSinhGordon() { 044 045 compareModels("Comparing product model with Sinh b=1", 046 new SinhGordonModel(1.0), 047 new ProductModel( new Object[]{ new Double(1.0)} ) 048 ); 049 050 compareModels("Comparing product model with Sinh b=0.5", 051 new SinhGordonModel(0.5), 052 new ProductModel( new Object[]{ new Double(0.5)} ) 053 ); 054 055 } 056 057 /** 058 * Verifies the product model against the Ising model. 059 */ 060 @Test 061 public void comparisonWithIsing() { 062 063 compareModels("Comparing product model with Ising", 064 new IsingModel(), 065 new ProductModel( new Object[]{}, true ) 066 ); 067 068 } 069 070 /** 071 * Verifies the product model against the sinh-Gordon model with an additional minus sign ("sinh-Ising model"). 072 */ 073 @Test 074 public void comparisonWithSinhIsing() { 075 076 compareModels("Comparing product model with Sinh-Ising b=1", 077 new SinhIsingModel(1.0), 078 new ProductModel( new Object[]{ 1.0 }, true ) 079 ); 080 081 compareModels("Comparing product model with Sinh-Ising b=0.5", 082 new SinhIsingModel(0.5), 083 new ProductModel( new Object[]{ 0.5 }, true ) 084 ); 085 086 } 087 088 /** 089 * Verifies the product model against a manually computed product of S-matrices from three sinh-Gordon models. 090 * 091 * Note that the minimal solution of the product model is obtained by the product of the minimal solutions 092 * in the sinh-Gordon models, with an additional factor of \( \big(\cosh (\zeta/2)\big)^{-2} \). 093 */ 094 @Test 095 public void comparisonWithSinhProduct() { 096 IntegrableModel[] sinhM = { new SinhGordonModel(1.0), 097 new SinhGordonModel(0.7), 098 new SinhGordonModel(0.3) }; 099 100 IntegrableModel product = new ProductModel( new Object[] {1.0, 0.7, 0.3} ); 101 102 compareModels("Comparing product of three sinh-Gordons", sinhM, -2, product); 103 } 104 105}