<commit_before>package com.sirenian.hellbound.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JFrame;

import org.jbehave.core.mock.Matcher;
import org.jbehave.core.mock.UsingMatchers;

import com.sirenian.hellbound.Hellbound;
import com.sirenian.hellbound.domain.Segment;
import com.sirenian.hellbound.domain.Segments;
import com.sirenian.hellbound.domain.glyph.GlyphType;

public class PitPanelBehaviour extends UsingMatchers {

	// Can't yet find a way of checking the colours in the pit!
	
	private static final int HEIGHT = 5;
	private static final int WIDTH = 4;
	private static final int SCALE = 50;
    private static final TypeAndColorMap COLORMAP = new TypeAndColorMap(new GlyphType[]{GlyphType.O, GlyphType.PIT}, new Color[]{Color.RED, Color.BLACK});

	Segments INITIAL_SEGMENTS = new Segments (
			new Segment(1, 2),
			new Segment(1, 3),
			new Segment(2, 3),
			new Segment(3, 3)
	);	
	
	Segments FINAL_SEGMENTS = new Segments (
			new Segment(1, 3),
			new Segment(1, 4),
			new Segment(2, 4),
			new Segment(3, 4)
	);
	
	public void shouldBeScaledToFitThePit() {
		JFrame frame = new JFrame();
		PitPanel panel = new PitPanel(SCALE, WIDTH, HEIGHT, Hellbound.COLORMAP);		
		frame.getContentPane().add(panel);
		frame.setVisible(true);		
		ensureThat(panel.getPreferredSize(), eq(new Dimension(200, 250)));		
		frame.dispose();
	}
	
	public void shouldDrawGlyphsAndRepaintWithNoError() {
		
		final RenderedPit renderedPit = new RenderedPit(SCALE, WIDTH, HEIGHT, COLORMAP);
		
		PitPanel panel = createPitPanelWithDoublePaint(renderedPit);

		JFrame frame = createFrameAndDisplay(panel);
		
		panel.reportGlyphMovement(GlyphType.O, new Segments(new Segment[0]), INITIAL_SEGMENTS);
		
		panel.repaint();
		frame.dispose();		
        
        ensureThat(renderedPit, contains(INITIAL_SEGMENTS, Color.RED));
	}

	public void shouldCleanGlyphsAfterMovement() {
		
		RenderedPit renderedPit = new RenderedPit(SCALE, WIDTH, HEIGHT, COLORMAP);
		PitPanel panel = createPitPanelWithDoublePaint(renderedPit);

		JFrame frame = createFrameAndDisplay(panel);
			
		
		panel.reportGlyphMovement(GlyphType.O, Segments.EMPTY, INITIAL_SEGMENTS);
		
		panel.reportGlyphMovement(GlyphType.O, INITIAL_SEGMENTS, FINAL_SEGMENTS);
		
		panel.repaint();
		frame.dispose();		
		
		ensureThat(renderedPit, contains(FINAL_SEGMENTS, Color.RED));
	}
    
    public void shouldNotCleanGlyphsOfOtherTypesAfterMovement() {
        
        RenderedPit renderedPit = new RenderedPit(SCALE, WIDTH, HEIGHT, COLORMAP);
        PitPanel panel = createPitPanelWithDoublePaint(renderedPit);

        JFrame frame = createFrameAndDisplay(panel);
            
        panel.reportGlyphMovement(GlyphType.O, Segments.EMPTY, INITIAL_SEGMENTS);
        panel.reportGlyphMovement(GlyphType.T, INITIAL_SEGMENTS, Segments.EMPTY);
        
        panel.repaint();
        frame.dispose();        
        
        ensureThat(renderedPit, contains(INITIAL_SEGMENTS, Color.RED));
    }    

	private JFrame createFrameAndDisplay(PitPanel panel) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(panel);
		frame.pack();
		frame.setVisible(true);
		return frame;
	}

	private PitPanel createPitPanelWithDoublePaint(final RenderedPit pg) {
		PitPanel panel = new PitPanel(SCALE, WIDTH, HEIGHT, Hellbound.COLORMAP) {

			private static final long serialVersionUID = 1L;

			public void paint(Graphics g) {
				super.paint(g);
				super.paint(pg);
			}
		};
		return panel;
	}
    
    private Matcher contains(final Segments segments, final Color color) {
        return new Matcher() {
            public boolean matches(Object arg) {
                return ((RenderedPit)arg).contains(segments, color);
            }
            
            public String toString() {                
                StringBuffer buffer = new StringBuffer();
                buffer.append("something containing ").append(System.getProperty("line.separator"));

                for (int y = 0; y < HEIGHT; y++) {
                    for (int x = 0; x < WIDTH; x++) {<commit_msg>[EK] Adding the HeadlessChecker to the behaviours (how did these ever work?!)<commit_after>package com.sirenian.hellbound.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JFrame;

import org.jbehave.core.mock.Matcher;
import org.jbehave.core.mock.UsingMatchers;
import org.jbehave.threaded.swing.HeadlessChecker;

import com.sirenian.hellbound.Hellbound;
import com.sirenian.hellbound.domain.Segment;
import com.sirenian.hellbound.domain.Segments;
import com.sirenian.hellbound.domain.glyph.GlyphType;

public class PitPanelBehaviour extends UsingMatchers {

	// Can't yet find a way of checking the colours in the pit!
	
	private static final int HEIGHT = 5;
	private static final int WIDTH = 4;
	private static final int SCALE = 50;
    private static final TypeAndColorMap COLORMAP = new TypeAndColorMap(new GlyphType[]{GlyphType.O, GlyphType.PIT}, new Color[]{Color.RED, Color.BLACK});

	Segments INITIAL_SEGMENTS = new Segments (
			new Segment(1, 2),
			new Segment(1, 3),
			new Segment(2, 3),
			new Segment(3, 3)
	);	
	
	Segments FINAL_SEGMENTS = new Segments (
			new Segment(1, 3),
			new Segment(1, 4),
			new Segment(2, 4),
			new Segment(3, 4)
	);
	
	public void shouldBeScaledToFitThePit() {
		new HeadlessChecker().check();
		JFrame frame = new JFrame();
		PitPanel panel = new PitPanel(SCALE, WIDTH, HEIGHT, Hellbound.COLORMAP);		
		frame.getContentPane().add(panel);
		frame.setVisible(true);		
		ensureThat(panel.getPreferredSize(), eq(new Dimension(200, 250)));		
		frame.dispose();
	}
	
	public void shouldDrawGlyphsAndRepaintWithNoError() {
		new HeadlessChecker().check();
		
		final RenderedPit renderedPit = new RenderedPit(SCALE, WIDTH, HEIGHT, COLORMAP);
		
		PitPanel panel = createPitPanelWithDoublePaint(renderedPit);

		JFrame frame = createFrameAndDisplay(panel);
		
		panel.reportGlyphMovement(GlyphType.O, new Segments(new Segment[0]), INITIAL_SEGMENTS);
		
		panel.repaint();
		frame.dispose();		
        
        ensureThat(renderedPit, contains(INITIAL_SEGMENTS, Color.RED));
	}

	public void shouldCleanGlyphsAfterMovement() {
		new HeadlessChecker().check();
		
		RenderedPit renderedPit = new RenderedPit(SCALE, WIDTH, HEIGHT, COLORMAP);
		PitPanel panel = createPitPanelWithDoublePaint(renderedPit);

		JFrame frame = createFrameAndDisplay(panel);
			
		
		panel.reportGlyphMovement(GlyphType.O, Segments.EMPTY, INITIAL_SEGMENTS);
		
		panel.reportGlyphMovement(GlyphType.O, INITIAL_SEGMENTS, FINAL_SEGMENTS);
		
		panel.repaint();
		frame.dispose();		
		
		ensureThat(renderedPit, contains(FINAL_SEGMENTS, Color.RED));
	}
    
    public void shouldNotCleanGlyphsOfOtherTypesAfterMovement() {
		new HeadlessChecker().check();
        
        RenderedPit renderedPit = new RenderedPit(SCALE, WIDTH, HEIGHT, COLORMAP);
        PitPanel panel = createPitPanelWithDoublePaint(renderedPit);

        JFrame frame = createFrameAndDisplay(panel);
            
        panel.reportGlyphMovement(GlyphType.O, Segments.EMPTY, INITIAL_SEGMENTS);
        panel.reportGlyphMovement(GlyphType.T, INITIAL_SEGMENTS, Segments.EMPTY);
        
        panel.repaint();
        frame.dispose();        
        
        ensureThat(renderedPit, contains(INITIAL_SEGMENTS, Color.RED));
    }    

	private JFrame createFrameAndDisplay(PitPanel panel) {
		new HeadlessChecker().check();
		JFrame frame = new JFrame();
		frame.getContentPane().add(panel);
		frame.pack();
		frame.setVisible(true);
		return frame;
	}

	private PitPanel createPitPanelWithDoublePaint(final RenderedPit pg) {
		new HeadlessChecker().check();
		PitPanel panel = new PitPanel(SCALE, WIDTH, HEIGHT, Hellbound.COLORMAP) {

			private static final long serialVersionUID = 1L;

			public void paint(Graphics g) {
				super.paint(g);
				super.paint(pg);
			}
		};
		return panel;
	}
    
    private Matcher contains(final Segments segments, final Color color) {
        return new Matcher() {
            public boolean matches(Object arg) {
                return ((RenderedPit)arg).contains(segments, color);
            }
            
            public String toString() {                
                StringBuffer buffer = new StringBuffer();
                buffer.append("something containing ").append(System.getProperty("line.separator"));

                for (int y = 0; y < HEIGHT; y++) {
                    for (int x = 0; x < WIDTH; x++) {
{'fraction_non_alphanumeric': 0.1043652194375809, 'fraction_numerical': 0.0070596540769502295, 'mean_word_length': 3.526091586794462, 'pattern_counts': {'":': 0, '<': 7, '<?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': '834774', 'n_tokens_mistral': 3069, 'n_tokens_neox': 2715, 'n_words': 593}