<commit_before>// Copyright 2016 PlanBase Inc. & <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.organicdesign.fp.experimental;

import org.junit.Test;
import org.organicdesign.fp.collections.ImList;
import org.organicdesign.fp.collections.UnmodListTest;

import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

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

public class RrbTree1Test {
    @Test
    public void insertAtZero() {
        final int SEVERAL = 100; //0; //0; //SecureRandom.getInstanceStrong().nextInt(999999) + 33 ;
        RrbTree1<Integer> is = RrbTree1.empty();
        ArrayList<Integer> control = new ArrayList<>();
        for (int j = 0; j < SEVERAL; j++){
            is = is.insert(0, j);
            control.add(0, j);
            assertEquals(j + 1, is.size());
            assertEquals(Integer.valueOf(j), is.get(0));
//            System.out.println(" ==" + is);
            for (int k = 0; k <= j; k++) {
                assertEquals("Checking index: " + k + " for size=" + control.size(), control.get(k), is.get(k));
            }
//            System.out.println(is);
        }
        assertEquals(SEVERAL, is.size());
        for (int j = 0; j < SEVERAL; j++){
            assertEquals(Integer.valueOf(SEVERAL - j - 1), is.get(j));
        }
    }

    Random rand = new Random();
    private int mutableRandIdx = 0;
//    private int[] myRands = new int[] {0, 0, 2, 2, 2, 3, 5, 1};
//    private int[] myRands = new int[] {0, 1, 2, 1, 0, 5, 2};
//    private int[] myRands = new int[] {0, 0, 1, 2, 3, 0, 1, 5, 8, 2};
    private int[] myRands = new int[] {0, 1, 2, 2, 3, 2, 0, 6, 5, 6, 9, 9, 5, 6, 14, 2, 12, 8, 15};
    private int myRand(int max) {
//       return rand.nextInt(max);

        // Don't want to modulo this - want to see this blow up to know that previous error
        // condition was cleared.
        return myRands[mutableRandIdx++]; // % myRands.length];
    }

    @Test
//    @Ignore
    public void insertRandom() {
        final int SEVERAL = 100; //0; //0; //SecureRandom.getInstanceStrong().nextInt(999999) + 33 ;
        RrbTree1<Integer> is = RrbTree1.empty();
        ArrayList<Integer> control = new ArrayList<>();
        ArrayList<Integer> rands = new ArrayList<>();
        for (int j = 0; j < SEVERAL; j++){
            int idx = myRand(is.size() + 1); //rand.nextInt(is.size() + 1);<commit_msg>Made an actual test for canned random-insert orderings that failed before.  The canned patterns will only work for radix=4, but won't hurt to keep around in case we ever go back to 4 for testing.<commit_after>// Copyright 2016 PlanBase Inc. & <NAME>erson
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.organicdesign.fp.experimental;

import org.junit.Ignore;
import org.junit.Test;
import org.organicdesign.fp.collections.ImList;
import org.organicdesign.fp.collections.UnmodListTest;

import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

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

public class RrbTree1Test {
    @Test
    public void insertAtZero() {
        final int SEVERAL = 100; //0; //0; //SecureRandom.getInstanceStrong().nextInt(999999) + 33 ;
        RrbTree1<Integer> is = RrbTree1.empty();
        ArrayList<Integer> control = new ArrayList<>();
        for (int j = 0; j < SEVERAL; j++){
            is = is.insert(0, j);
            control.add(0, j);
            assertEquals(j + 1, is.size());
            assertEquals(Integer.valueOf(j), is.get(0));
//            System.out.println(" ==" + is);
            for (int k = 0; k <= j; k++) {
                assertEquals("Checking index: " + k + " for size=" + control.size(), control.get(k), is.get(k));
            }
//            System.out.println(is);
        }
        assertEquals(SEVERAL, is.size());
        for (int j = 0; j < SEVERAL; j++){
            assertEquals(Integer.valueOf(SEVERAL - j - 1), is.get(j));
        }
    }

    public <T> void randomInsertTest(int[] indices) {
        RrbTree1<Integer> is = RrbTree1.empty();
        ArrayList<Integer> control = new ArrayList<>();
        for (int j = 0; j < indices.length; j++){
            int idx = indices[j];
            is = is.insert(idx, j);
            control.add(idx, j);
            assertEquals("size", j + 1, is.size());
            assertEquals("item at " + idx, Integer.valueOf(j), is.get(idx));
//            System.out.println("control:" + control);
//            System.out.println("===test:" + is);
            for (int k = 0; k <= j; k++) {
                assertEquals("item at " + k + " still correct at size " + is.size(),
                             control.get(k), is.get(k));
//                System.out.println("control[" + k + "]:" + control.get(k) + " test[" + k + "]:" + is.get(k));
            }
        }
//        assertEquals(indices.length, is.size());
//        for (int j = 0; j < indices.length; j++){
//            assertEquals(control.get(j), is.get(j));
//        }
    }

    @Test public void insertRandPrevFail() {
        randomInsertTest(new int[] {0, 0, 2, 2, 2, 3, 5, 1});
        randomInsertTest(new int[] {0, 1, 2, 1, 0, 5, 2});
        randomInsertTest(new int[] {0, 0, 1, 2, 3, 0, 1, 5, 8, 2});
//        randomInsertTest(new int[] {0, 1, 2, 2, 3, 2, 0, 6, 5, 6, 9, 9, 5, 6, 14, 2, 12, 8, 15});
    }

    Random rand = new java.security.SecureRandom();
    @Test
    @Ignore
    public void insertRandom() {
        final int SEVERAL = 100; //0; //0; //SecureRandom.getInstanceStrong().nextInt(999999) + 33 ;
        RrbTree1<Integer> is = RrbTree1.empty();
        ArrayList<Integer> control = new ArrayList<>();
        ArrayList<Integer> rands = new ArrayList<>();
        for (int j = 0; j < SEVERAL; j++){
            int idx = rand.nextInt(is.size() + 1);
{'fraction_non_alphanumeric': 0.14946569178852642, 'fraction_numerical': 0.02840269966254218, 'mean_word_length': 2.4748412310698584, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5107253', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2155, 'n_words': 701}