<commit_before>// Tests
// tflorez

import java.util.ArrayList;

void runTests() {

  Tester tester = new Tester("RelativityTests", 7);
  tester.verbose = false;
  
  // Sanity Check
  tester.ok(1 == 1, "Sanity check: 1 == 1");
  
  // Use velocity of 0.9 c in x-direction
  Velocity vel = new Velocity(0.9f, 0);

  // Use vector (1, 0, 0)
  Vector3f v1 = new Vector3f(1, 0, 0);

  // Do Lorentz transformation
  Vector3f vLorentz = new Vector3f();
  Relativity.lorentzTransform(vel, v1, vLorentz);
  
  // Test Gamma
  float gamma = 1.0f / (float) Math.sqrt(1 - pow(0.9f, 2));
  
  tester.ok( vel.gamma == gamma
             && abs(gamma - 2.29416) < 0.01,
             "Gamma(0.9 c) should be: 2.29416" );
  
  // Calculate expectation value for vector 1, 0, 0
  float xprime = gamma * (v1.x - 0);
  float tprime = gamma * (0 - vel.vx * v1.x);
  
  Vector3f vExpect = new Vector3f(xprime, 0, tprime);
  Vector3f vExpectByHand = new Vector3f(2.29416, 0, -2.06474);
  <commit_msg>Latest. Test momentum conservation in particle decay.<commit_after>// Tests
// tflorez

import java.util.ArrayList;

void runTests() {
  runRelativityTests();
  runParticleTests();
}

void runParticleTests() {
  
  Tester tester = new Tester("ParticleTests", 1);
  tester.verbose = true;
  
  // Use position of (x, y) = (100, 100) in ls
  Vector3f pos = new Vector3f(100, 100, 0);
  
  // Use velocity of 0.9 c in the y-direction
  Velocity vel = new Velocity(0, 0.9f);
  
  // Init Lorentz matrix for particle creation
  lorentzMatrix = Relativity.getLorentzTransformMatrix(vel);
  inverseLorentzMatrix = Relativity.getInverseLorentzTransformMatrix(vel);
  
  // Create test particle with mass of 100 kg
  Particle p = new Particle(100, pos, vel);
  
  
  // Particle Decay
  
  double mass = Math.random() * 1000;
  Particle decayParticle = new Particle(mass, new Vector3f(), new Velocity(0, 0));
  
  double m1 = Math.random() * mass;
  double m2 = Math.random() * (mass - m1);
  double angle = Math.random() * TWO_PI;
  
  List decayProducts = decayParticle.simulateSplitDecay(m1, m2, angle);
  
  Particle p1 = (Particle) decayProducts.get(0);
  Particle p2 = (Particle) decayProducts.get(1);
  
  tester.ok(percentDiff(p1.getMomentum(), p2.getMomentum()) < 0.1,
            "Momenta in split decay should be equal and opposite in rest frame.");
  
  print(tester.getResultSummary());
}

/**
 *  Find the absolute percent difference between two values:
 *  percentDiff = | 100 * (diff / average) |
 */
double percentDiff(double a, double b) {
  
  double avg = (a + b) / 2.0;
  double diff = b - a;
  
  return Math.abs(100.0 * diff / avg);
}

void runRelativityTests() {
  Tester tester = new Tester("RelativityTests", 7);
  tester.verbose = false;
  
  // Sanity Check
  tester.ok(1 == 1, "Sanity check: 1 == 1");
  
  // Use velocity of 0.9 c in x-direction
  Velocity vel = new Velocity(0.9f, 0);

  // Use vector (1, 0, 0)
  Vector3f v1 = new Vector3f(1, 0, 0);

  // Do Lorentz transformation
  Vector3f vLorentz = new Vector3f();
  Relativity.lorentzTransform(vel, v1, vLorentz);
  
  // Test Gamma
  float gamma = 1.0f / (float) Math.sqrt(1 - pow(0.9f, 2));
  
  tester.ok( vel.gamma == gamma
             && abs(gamma - 2.29416) < 0.01,
             "Gamma(0.9 c) should be: 2.29416" );
  
  // Calculate expectation value for vector 1, 0, 0
  float xprime = gamma * (v1.x - 0);
  float tprime = gamma * (0 - vel.vx * v1.x);
  
  Vector3f vExpect = new Vector3f(xprime, 0, tprime);
  Vector3f vExpectByHand = new Vector3f(2.29416, 0, -2.06474);
  
{'fraction_non_alphanumeric': 0.13664596273291926, 'fraction_numerical': 0.05533596837944664, 'mean_word_length': 2.897689768976898, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5054861', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1289, 'n_words': 370}