<commit_before>/**
 * Copyright (C) 2009 - 2009 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.math.number;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.Test;

/**
 * 
 */
public class ComplexNumberTest {

  @Test
  public void test() {
    final ComplexNumber z1 = new ComplexNumber(1, 2);
    final ComplexNumber z2 = new ComplexNumber(1, 2);
    assertEquals(Double.valueOf(1), Double.valueOf(z1.getReal()));
    assertEquals(Double.valueOf(2), Double.valueOf(z1.getImaginary()));
    assertEquals(z1, z2);
    try {
      z1.byteValue();
      fail();
    } catch (final UnsupportedOperationException e) {
      // Expected
    }
    try {
      z1.intValue();
      fail();
    } catch (final UnsupportedOperationException e) {
      // Expected
    }
    try {
      z1.longValue();
      fail();
    } catch (final UnsupportedOperationException e) {
      // Expected
    }
    try {
      z1.floatValue();
      fail();
    } catch (final UnsupportedOperationException e) {
      // Expected
    }
    try {
      z1.doubleValue();
      fail();
    } catch (final UnsupportedOperationException e) {
      // Expected
    }
    assertEquals("1.0 + 2.0i", z1.toString());
    assertEquals("1.0", new ComplexNumber(1, 0).toString());
    assertEquals("2.3i", new ComplexNumber(0, 2.3).toString());
  }
}<commit_msg>[ANA-76] Tidying up complex number test and added more equals() and hashCode() tests<commit_after>/**
 * Copyright (C) 2009 - 2009 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.math.number;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import org.junit.Test;

/**
 * 
 */
public class ComplexNumberTest {
  private static final ComplexNumber Z1 = new ComplexNumber(1, 2);
  private static final ComplexNumber Z2 = new ComplexNumber(1, 2);
  private static final ComplexNumber Z3 = new ComplexNumber(1, 3);
  private static final ComplexNumber Z4 = new ComplexNumber(2, 2);
  private static final ComplexNumber Z5 = new ComplexNumber(2, 3);

  @Test(expected = UnsupportedOperationException.class)
  public void testByteValue() {
    Z1.byteValue();
  }

  @Test(expected = UnsupportedOperationException.class)
  public void testIntValue() {
    Z1.intValue();
  }

  @Test(expected = UnsupportedOperationException.class)
  public void testLongValue() {
    Z1.longValue();
  }

  @Test(expected = UnsupportedOperationException.class)
  public void testFloatValue() {
    Z1.floatValue();
  }

  @Test(expected = UnsupportedOperationException.class)
  public void testDoubleValue() {
    Z1.doubleValue();
  }

  @Test
  public void test() {
    assertEquals(Double.valueOf(1), Double.valueOf(Z1.getReal()));
    assertEquals(Double.valueOf(2), Double.valueOf(Z1.getImaginary()));
    assertEquals(Z1, Z2);
    assertEquals(Z1.hashCode(), Z2.hashCode());
    assertEquals("1.0 + 2.0i", Z1.toString());
    assertEquals("1.0", new ComplexNumber(1, 0).toString());
    assertEquals("2.3i", new ComplexNumber(0, 2.3).toString());
    assertFalse(Z1.equals(Z3));
    assertFalse(Z1.equals(Z4));
    assertFalse(Z1.equals(Z5));
  }
}
{'fraction_non_alphanumeric': 0.13498452012383902, 'fraction_numerical': 0.030030959752321982, 'mean_word_length': 3.48127600554785, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1887822', 'n_tokens_mistral': 1031, 'n_tokens_neox': 988, 'n_words': 233}