<commit_before>package com.mijecu25.dsa.algorithms.swap;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import com.mijecu25.dsa.algorithms.swap.XORSwap;


/**
 * Test for XORSwap class.
 * 
 * @author <NAME>
 * @version 0.1.3.3
 */
public class TestXORSwap {
	private int[] list1 = {1, 2, 3, 4};
	private int[] list2 = {5, 6, 7, 8};
	
	@Before
	public void initialize() {
		;
	}	
	
	/**
	 * Test swap(int[] intArray1, int array1Index, int[] intArray2, int array2Index)
	 */
	@Test 
	public void swap1() {
		// Get the first and second element of the first and second lists
		int a = this.list1[0];
		int b = this.list2[1];
		
		// Swap the first element of the first list with the last element
		// of the second list
		XORSwap.swap(this.list1, 0, this.list2, 1);
		
		// Assert that the values were swapped
		Assert.assertTrue(this.list1[0] == b);
		Assert.assertTrue(this.list2[1] == a);
	}
	
	/**
	 * Test swap(int[] intArray1, int[] intArray2, int index)
	 */
	@Test
	public void swap2() {
		// Get the last elements of both lists
		int a = this.list1[this.list1.length-1];
		int b = this.list2[this.list2.length-1];
		
		// Swap the last elements
		XORSwap.swap(this.list1, this.list2, this.list1.length-1);
		
		// Assert that the values were swapped
		Assert.assertTrue(this.list1[this.list1.length-1] == b);
		Assert.assertTrue(this.list2[this.list2.length-1] == a);	
	}
	
	/**
	 * Test swap(int[] intArray1, int[] intArray2)
	 */
	@Test
	public void swap3() {
		// Get the lists
		int[] a = new int[this.list1.length];
		System.arraycopy(this.list1, 0, a, 0, this.list1.length);
		int[] b = new int[this.list2.length];
		System.arraycopy(this.list2, 0, b, 0, this.list2.length);
		
		// Swap the last elements
		XORSwap.swap(this.list1, this.list2);
		
		// Assert that the values were swapped
		for(int i = 0; i < this.list1.length; i++) {
			Assert.assertTrue(this.list1[i] == b[i]);
			Assert.assertTrue(this.list2[i] == a[i]);			
		}
				
		// Try swapping lists of different lengths
		XORSwap.swap(this.list1, new int[0]);
	}
	
}<commit_msg>New test for swapping elements of the same array<commit_after>package com.mijecu25.dsa.algorithms.swap;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import com.mijecu25.dsa.algorithms.swap.XORSwap;


/**
 * Test for XORSwap class.
 * 
 * @author <NAME>
 * @version 0.1.3.4
 */
public class TestXORSwap {
	private int[] list1 = {1, 2, 3, 4};
	private int[] list2 = {5, 6, 7, 8};
	
	@Before
	public void initialize() {
		;
	}	
	
	/**
	 * Test swap(int[] intArray1, int array1Index, int[] intArray2, int array2Index)
	 */
	@Test 
	public void swap1() {
		// Get the first and second element of the first and second lists
		int a = this.list1[0];
		int b = this.list2[1];
		
		// Swap the first element of the first list with the last element
		// of the second list
		XORSwap.swap(this.list1, 0, this.list2, 1);
		
		// Assert that the values were swapped
		Assert.assertTrue(this.list1[0] == b);
		Assert.assertTrue(this.list2[1] == a);
	}
	
	/**
	 * Test swap(int[] intArray1, int[] intArray2, int index)
	 */
	@Test
	public void swap2() {
		// Get the last elements of both lists
		int a = this.list1[this.list1.length-1];
		int b = this.list2[this.list2.length-1];
		
		// Swap the last elements
		XORSwap.swap(this.list1, this.list2, this.list1.length-1);
		
		// Assert that the values were swapped
		Assert.assertTrue(this.list1[this.list1.length-1] == b);
		Assert.assertTrue(this.list2[this.list2.length-1] == a);	
	}
	
	/**
	 * Test swap(int[] intArray1, int[] intArray2)
	 */
	@Test
	public void swap3() {
		// Get the lists
		int[] a = new int[this.list1.length];
		System.arraycopy(this.list1, 0, a, 0, this.list1.length);
		int[] b = new int[this.list2.length];
		System.arraycopy(this.list2, 0, b, 0, this.list2.length);
		
		// Swap the last elements
		XORSwap.swap(this.list1, this.list2);
		
		// Assert that the values were swapped
		for(int i = 0; i < this.list1.length; i++) {
			Assert.assertTrue(this.list1[i] == b[i]);
			Assert.assertTrue(this.list2[i] == a[i]);			
		}
				
		// Try swapping lists of different lengths
		XORSwap.swap(this.list1, new int[0]);
	}

	/**
	 * Test swap(int[] intArray1, int index1, int index2)
	 */
	@Test
	public void swap4() {
		// Get elements from a list
		int a = this.list1[this.list1.length-1];
		int b = this.list1[0];

		// Swap the last elements
		XORSwap.swap(this.list1, 0, this.list1.length-1);

		// Assert that the values were swapped
		Assert.assertTrue(this.list1[this.list1.length-1] == b);
		Assert.assertTrue(this.list1[0] == a);
	}
	
}
{'fraction_non_alphanumeric': 0.15175752473163545, 'fraction_numerical': 0.03536097663649758, 'mean_word_length': 3.168421052631579, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2496019', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1782, 'n_words': 459}