<commit_before>import { action, observable } from "mobx";
import uuidv4 from "uuid/v4";
import Command from "./Command";

export default class TestCase {
  id = null;
  @observable name = null;
  @observable commands = [];

  constructor(id = uuidv4(), name = "<NAME>") {
    this.id = id;
    this.name = name;
    this.createCommand = this.createCommand.bind(this);
    this.removeCommand = this.removeCommand.bind(this);
  }

  @action createCommand() {
    const command = new Command();
    this.commands.push(command);
    return command;
  }

  @action insertCommandAt(command, index) {
    if (!command || command.constructor.name !== "Command") {
      throw new Error(`Expected to receive Command instead received ${command ? command.constructor.name : command}`);
    } else if (!index || index.constructor.name !== "Number") {
      throw new Error(`Expected to receive Number instead received ${index ? index.constructor.name : index}`);
    } else {
      this.commands.splice(index, 0, command);
    }
  }

  @action removeCommand(command) {
    this.commands.remove(command);
  }
}
<commit_msg>swapcommands function<commit_after>import { action, observable } from "mobx";
import uuidv4 from "uuid/v4";
import Command from "./Command";

export default class TestCase {
  id = null;
  @observable name = null;
  @observable commands = [];

  constructor(id = uuidv4(), name = "<NAME>") {
    this.id = id;
    this.name = name;
    this.createCommand = this.createCommand.bind(this);
    this.removeCommand = this.removeCommand.bind(this);
  }

  @action createCommand() {
    const command = new Command();
    this.commands.push(command);
    return command;
  }

  @action insertCommandAt(command, index) {
    if (!command || command.constructor.name !== "Command") {
      throw new Error(`Expected to receive Command instead received ${command ? command.constructor.name : command}`);
    } else if (!index || index.constructor.name !== "Number") {
      throw new Error(`Expected to receive Number instead received ${index ? index.constructor.name : index}`);
    } else {
      this.commands.splice(index, 0, command);
    }
  }

  @action swapCommands(from, to) {
    const command = this.commands.splice(from, 1)[0];
    this.insertCommandAt(command, to);
  }

  @action removeCommand(command) {
    this.commands.remove(command);
  }
}

{'fraction_non_alphanumeric': 0.1397712833545108, 'fraction_numerical': 0.004235493434985175, 'mean_word_length': 3.61328125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '744070', 'n_tokens_mistral': 696, 'n_tokens_neox': 692, 'n_words': 182}