<commit_before>package com.io7m.jsycamore.tests;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.junit.Assert;
import org.junit.Test;

import com.io7m.jaux.ApproximatelyEqualFloat;
import com.io7m.jaux.Constraints.ConstraintError;
import com.io7m.jsycamore.GUIException;
import com.io7m.jsycamore.GUIException.ErrorCode;
import com.io7m.jsycamore.Theme;
import com.io7m.jsycamore.Version;
import com.io7m.jtensors.VectorReadable3F;

public class ThemeTest
{
  private static boolean fequal(
    final float e,
    final float a)
  {
    return ApproximatelyEqualFloat.approximatelyEqual(e, a);
  }

  @Test(expected = GUIException.class) public
    void
    testBadVectorInvalidNumberFormat()
      throws GUIException,
        ConstraintError
  {
    final Properties p = new Properties();
    p.setProperty(
      "jsycamore.theme.version",
      Integer.toString(Version.THEME_VERSION));
    p.setProperty("jsycamore.theme.bounds_color", "x y z");

    try {
      Theme.loadThemeFromProperties(p);
    } catch (final GUIException e) {
      Assert.assertEquals(
        ErrorCode.GUI_THEME_VALUE_INCORRECT_TYPE,
        e.getErrorCode());
      throw e;
    }

    Assert.fail("unreachable");
  }

  @Test(expected = GUIException.class) public
    void
    testBadVectorInvalidNumberRange()
      throws GUIException,
        ConstraintError
  {
    final Properties p = new Properties();
    p.setProperty(
      "jsycamore.theme.version",
      Integer.toString(Version.THEME_VERSION));
    p.setProperty("jsycamore.theme.bounds_color", "2.0 0.0 0.0");

    try {
      Theme.loadThemeFromProperties(p);
    } catch (final GUIException e) {
      Assert.assertEquals(
        ErrorCode.GUI_THEME_VALUE_INCORRECT_TYPE,
        e.getErrorCode());
      throw e;
    }

    Assert.fail("unreachable");
  }

  @Test(expected = GUIException.class) public
    void
    testBadVectorInvalidUtterly()
      throws GUIException,
        ConstraintError
  {
    final Properties p = new Properties();
    p.setProperty(
      "jsycamore.theme.version",
      Integer.toString(Version.THEME_VERSION));
    p.setProperty("jsycamore.theme.bounds_color", "x");

    try {
      Theme.loadThemeFromProperties(p);
    } catch (final GUIException e) {
      Assert.assertEquals(
        ErrorCode.GUI_THEME_VALUE_INCORRECT_TYPE,
        e.getErrorCode());
      throw e;
    }

    Assert.fail("unreachable");
  }

  @Test public void testCopy()
    throws GUIException,
      ConstraintError,
      IOException
  {
    final FileInputStream stream_w =
      new FileInputStream("src/main/resources/themes/debug_white.thm");
    final FileInputStream stream_b =
      new FileInputStream("src/main/resources/themes/debug_black.thm");

    final Properties p_w = new Properties();
    final Properties p_b = new Properties();

    p_w.load(stream_w);
    p_b.load(stream_b);

    final Theme t_w = Theme.loadThemeFromProperties(p_w);
    final Theme t_b = Theme.loadThemeFromProperties(p_b);

    /**
     * White.
     */

    /**
     * Focused.
     */

    {
      final VectorReadable3F v = t_w.getBoundsColor();
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getXF()));
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getYF()));
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getZF()));
    }

    {
      final VectorReadable3F v = t_w.getFailsafeColor();
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getXF()));
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getYF()));
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getZF()));
    }<commit_msg>Fix path for resources in test<commit_after>package com.io7m.jsycamore.tests;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.junit.Assert;
import org.junit.Test;

import com.io7m.jaux.ApproximatelyEqualFloat;
import com.io7m.jaux.Constraints.ConstraintError;
import com.io7m.jsycamore.GUIException;
import com.io7m.jsycamore.GUIException.ErrorCode;
import com.io7m.jsycamore.Theme;
import com.io7m.jsycamore.Version;
import com.io7m.jtensors.VectorReadable3F;

public class ThemeTest
{
  private static boolean fequal(
    final float e,
    final float a)
  {
    return ApproximatelyEqualFloat.approximatelyEqual(e, a);
  }

  @Test(expected = GUIException.class) public
    void
    testBadVectorInvalidNumberFormat()
      throws GUIException,
        ConstraintError
  {
    final Properties p = new Properties();
    p.setProperty(
      "jsycamore.theme.version",
      Integer.toString(Version.THEME_VERSION));
    p.setProperty("jsycamore.theme.bounds_color", "x y z");

    try {
      Theme.loadThemeFromProperties(p);
    } catch (final GUIException e) {
      Assert.assertEquals(
        ErrorCode.GUI_THEME_VALUE_INCORRECT_TYPE,
        e.getErrorCode());
      throw e;
    }

    Assert.fail("unreachable");
  }

  @Test(expected = GUIException.class) public
    void
    testBadVectorInvalidNumberRange()
      throws GUIException,
        ConstraintError
  {
    final Properties p = new Properties();
    p.setProperty(
      "jsycamore.theme.version",
      Integer.toString(Version.THEME_VERSION));
    p.setProperty("jsycamore.theme.bounds_color", "2.0 0.0 0.0");

    try {
      Theme.loadThemeFromProperties(p);
    } catch (final GUIException e) {
      Assert.assertEquals(
        ErrorCode.GUI_THEME_VALUE_INCORRECT_TYPE,
        e.getErrorCode());
      throw e;
    }

    Assert.fail("unreachable");
  }

  @Test(expected = GUIException.class) public
    void
    testBadVectorInvalidUtterly()
      throws GUIException,
        ConstraintError
  {
    final Properties p = new Properties();
    p.setProperty(
      "jsycamore.theme.version",
      Integer.toString(Version.THEME_VERSION));
    p.setProperty("jsycamore.theme.bounds_color", "x");

    try {
      Theme.loadThemeFromProperties(p);
    } catch (final GUIException e) {
      Assert.assertEquals(
        ErrorCode.GUI_THEME_VALUE_INCORRECT_TYPE,
        e.getErrorCode());
      throw e;
    }

    Assert.fail("unreachable");
  }

  @Test public void testCopy()
    throws GUIException,
      ConstraintError,
      IOException
  {
    final FileInputStream stream_w =
      new FileInputStream(
        "src/main/resources/sycamore/themes/debug_white.thm");
    final FileInputStream stream_b =
      new FileInputStream(
        "src/main/resources/sycamore/themes/debug_black.thm");

    final Properties p_w = new Properties();
    final Properties p_b = new Properties();

    p_w.load(stream_w);
    p_b.load(stream_b);

    final Theme t_w = Theme.loadThemeFromProperties(p_w);
    final Theme t_b = Theme.loadThemeFromProperties(p_b);

    /**
     * White.
     */

    /**
     * Focused.
     */

    {
      final VectorReadable3F v = t_w.getBoundsColor();
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getXF()));
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getYF()));
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getZF()));
    }

    {
      final VectorReadable3F v = t_w.getFailsafeColor();
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getXF()));
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getYF()));
      Assert.assertTrue(ThemeTest.fequal(1.0f, v.getZF()));
    }
{'fraction_non_alphanumeric': 0.11366451080225677, 'fraction_numerical': 0.007981285262143938, 'mean_word_length': 3.115515288788222, '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': '526378', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2340, 'n_words': 399}