<commit_before>package com.metl.data

import org.scalatest._
import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfter
import org.scalatest.matchers.{ShouldMatchers, HavePropertyMatcher, HavePropertyMatchResult}
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.OptionValues._

import net.liftweb.util.Helpers._
import net.liftweb.common._
import scala.xml._
import com.metl.data._
import Privacy._

class MeTLHistorySuite extends FunSuite with GeneratorDrivenPropertyChecks with BeforeAndAfter with ShouldMatchers with QueryXml with MeTLTextMatchers with MeTLDataGenerators {
	test("add an ink") {
    val h = new History("test")
		forAll (genInk) { (ink: MeTLInk) =>
      h.addStanza(ink)
      h.getInks == List(ink) || h.getHighlighters == List(ink)
    }
	}
	test("add a textbox") {
    val h = new History("test")
		forAll (genText) { (text: MeTLText) =>
      h.addStanza(text)
      h.getTexts == List(text)
    }
	}
	test("add an image") {
    val h = new History("test")
		forAll (genImage) { (image: MeTLImage) =>
      h.addStanza(image)
      h.getImages == List(image)
    }
	}
	test("add a submission") {
    val h = new History("test")
		forAll (genSubmission) { (sub: MeTLSubmission) =>
      h.addStanza(sub)
      h.getSubmissions == List(sub)
    }
	}
	test("add a command") {
    val h = new History("test")
		forAll (genCommand) { (comm: MeTLCommand) =>
      h.addStanza(comm)
      h.getCommands == List(comm)
    }
	}
	test("add an ink and then delete it") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val dirtyInk = ink.generateDirty()
      h.addStanza(ink)
      h.addStanza(dirtyInk)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
    }
	}
	test("add an ink and then delete it and then undelete it") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val dirtyInk = ink.generateDirty()
      h.addStanza(ink)
      h.addStanza(dirtyInk)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
      h.getDeletedCanvasContents.foreach((undeletedInk:MeTLCanvasContent) => {
        val newUndeletedInk = undeletedInk.generateNewIdentity(nextFuncName).adjustTimestamp(ink.timestamp + 2)
        val undeleteMarker = MeTLUndeletedCanvasContent(undeletedInk.server,undeletedInk.author,undeletedInk.timestamp + 1,undeletedInk.target,undeletedInk.privacy,undeletedInk.slide,nextFuncName,"ink",ink.identity,newUndeletedInk.identity)
        h.addStanza(newUndeletedInk)
        h.addStanza(undeleteMarker)
        (h.getCanvasContents should contain (newUndeletedInk))
        (h.getUndeletedCanvasContents should contain (undeleteMarker))
      })
    }
  }
	test("add an ink and then delete it with a moveDelta") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val moveDelta = MeTLMoveDelta(ink.server,ink.author,ink.timestamp + 1,ink.target,ink.privacy,ink.slide,nextFuncName,0.0,0.0,List(ink.identity),Nil,Nil,Nil,Nil,0.0,0.0,1.0,1.0,Privacy.NOT_SET,true)
      h.addStanza(ink)
      h.addStanza(moveDelta)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
    }
	}
	test("add an ink and then delete it with a moveDelta and then undelete it") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val moveDelta = MeTLMoveDelta(ink.server,ink.author,ink.timestamp + 1,ink.target,ink.privacy,ink.slide,nextFuncName,0.0,0.0,List(ink.identity),Nil,Nil,Nil,Nil,0.0,0.0,1.0,1.0,Privacy.NOT_SET,true)
      h.addStanza(ink)
      h.addStanza(moveDelta)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
      h.getDeletedCanvasContents.foreach((undeletedInk:MeTLCanvasContent) => {
        val newUndeletedInk = undeletedInk.generateNewIdentity(nextFuncName).adjustTimestamp(ink.timestamp + 2)
        val undeleteMarker = MeTLUndeletedCanvasContent(undeletedInk.server,undeletedInk.author,undeletedInk.timestamp + 1,undeletedInk.target,undeletedInk.privacy,undeletedInk.slide,nextFuncName,"ink",ink.identity,newUndeletedInk.identity)
        h.addStanza(newUndeletedInk)
        h.addStanza(undeleteMarker)
        (h.getCanvasContents should contain (newUndeletedInk))
        (h.getUndeletedCanvasContents should contain (undeleteMarker))
      })
    }
	}

}<commit_msg>better tests around history since the undeletes<commit_after>package com.metl.data

import org.scalatest._
import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfter
import org.scalatest.matchers.{ShouldMatchers, HavePropertyMatcher, HavePropertyMatchResult}
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.OptionValues._

import net.liftweb.util.Helpers._
import net.liftweb.common._
import scala.xml._
import com.metl.data._
import Privacy._

class MeTLHistorySuite extends FunSuite with GeneratorDrivenPropertyChecks with BeforeAndAfter with ShouldMatchers with QueryXml with MeTLTextMatchers with MeTLDataGenerators {
	test("add an ink") {
    val h = new History("test")
		forAll (genInk) { (ink: MeTLInk) =>
      h.addStanza(ink)
      h.getInks == List(ink) || h.getHighlighters == List(ink)
    }
	}
	test("add a textbox") {
    val h = new History("test")
		forAll (genText) { (text: MeTLText) =>
      h.addStanza(text)
      h.getTexts == List(text)
    }
	}
	test("add an image") {
    val h = new History("test")
		forAll (genImage) { (image: MeTLImage) =>
      h.addStanza(image)
      h.getImages == List(image)
    }
	}
	test("add a submission") {
    val h = new History("test")
		forAll (genSubmission) { (sub: MeTLSubmission) =>
      h.addStanza(sub)
      h.getSubmissions == List(sub)
    }
	}
	test("add a command") {
    val h = new History("test")
		forAll (genCommand) { (comm: MeTLCommand) =>
      h.addStanza(comm)
      h.getCommands == List(comm)
    }
	}
	test("add an ink and then delete it") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val dirtyInk = ink.generateDirty()
      h.addStanza(ink)
      h.addStanza(dirtyInk)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
    }
	}
	test("add an ink and then delete it and then undelete it") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val dirtyInk = ink.generateDirty()
      h.addStanza(ink)
      h.addStanza(dirtyInk)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
      h.getDeletedCanvasContents.foreach((undeletedInk:MeTLCanvasContent) => {
        val newUndeletedInk = undeletedInk.generateNewIdentity(nextFuncName).adjustTimestamp(ink.timestamp + 2)
        val undeleteMarker = MeTLUndeletedCanvasContent(undeletedInk.server,undeletedInk.author,undeletedInk.timestamp + 1,undeletedInk.target,undeletedInk.privacy,undeletedInk.slide,nextFuncName,"ink",ink.identity,newUndeletedInk.identity)
        h.addStanza(newUndeletedInk)
        h.addStanza(undeleteMarker)
        (h.getCanvasContents should contain (newUndeletedInk))
        (h.getUndeletedCanvasContents should contain (undeleteMarker))
      })
    }
  }
	test("add an ink and then delete it with a moveDelta") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val moveDelta = MeTLMoveDelta(ink.server,ink.author,ink.timestamp + 1,ink.target,ink.privacy,ink.slide,nextFuncName,0.0,0.0,List(ink.identity),Nil,Nil,Nil,Nil,0.0,0.0,1.0,1.0,Privacy.NOT_SET,true)
      h.addStanza(ink)
      h.addStanza(moveDelta)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
    }
	}
	test("add an ink and then delete it with a moveDelta and then undelete it") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val moveDelta = MeTLMoveDelta(ink.server,ink.author,ink.timestamp + 1,ink.target,ink.privacy,ink.slide,nextFuncName,0.0,0.0,List(ink.identity),Nil,Nil,Nil,Nil,0.0,0.0,1.0,1.0,Privacy.NOT_SET,true)
      h.addStanza(ink)
      h.addStanza(moveDelta)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
      h.getDeletedCanvasContents.foreach((undeletedInk:MeTLCanvasContent) => {
        val newUndeletedInk = undeletedInk.generateNewIdentity(nextFuncName).adjustTimestamp(ink.timestamp + 2)
        val undeleteMarker = MeTLUndeletedCanvasContent(undeletedInk.server,undeletedInk.author,undeletedInk.timestamp + 1,undeletedInk.target,undeletedInk.privacy,undeletedInk.slide,nextFuncName,"ink",ink.identity,newUndeletedInk.identity)
        h.addStanza(newUndeletedInk)
        h.addStanza(undeleteMarker)
        (h.getCanvasContents should contain (newUndeletedInk))
        (h.getUndeletedCanvasContents should contain (undeleteMarker))
      })
    }
	}
	test("add an ink and then delete it with a moveDelta and then undelete it and then filter the history") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val moveDelta = MeTLMoveDelta(ink.server,ink.author,ink.timestamp + 1,ink.target,ink.privacy,ink.slide,nextFuncName,0.0,0.0,List(ink.identity),Nil,Nil,Nil,Nil,0.0,0.0,1.0,1.0,Privacy.NOT_SET,true)
      h.addStanza(ink)
      h.addStanza(moveDelta)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
      h.getDeletedCanvasContents.foreach((undeletedInk:MeTLCanvasContent) => {
        val newUndeletedInk = undeletedInk.generateNewIdentity(nextFuncName).adjustTimestamp(ink.timestamp + 2)
        val undeleteMarker = MeTLUndeletedCanvasContent(undeletedInk.server,undeletedInk.author,undeletedInk.timestamp + 1,undeletedInk.target,undeletedInk.privacy,undeletedInk.slide,nextFuncName,"ink",ink.identity,newUndeletedInk.identity)
        h.addStanza(newUndeletedInk)
        h.addStanza(undeleteMarker)
        val nh = h.filter(c => true)
        (nh.getCanvasContents should not contain (ink))
        (nh.getDeletedCanvasContents should contain (ink))
        (nh.getCanvasContents should contain (newUndeletedInk))
        (nh.getUndeletedCanvasContents should contain (undeleteMarker))
      })
    }
	}
	test("add an ink and then delete it with a moveDelta and then undelete it and then filter the history and then merge the history") {
		forAll (genInk) { (ink: MeTLInk) =>
      val h = new History("test")
      val moveDelta = MeTLMoveDelta(ink.server,ink.author,ink.timestamp + 1,ink.target,ink.privacy,ink.slide,nextFuncName,0.0,0.0,List(ink.identity),Nil,Nil,Nil,Nil,0.0,0.0,1.0,1.0,Privacy.NOT_SET,true)
      h.addStanza(ink)
      h.addStanza(moveDelta)
      (h.getCanvasContents should not contain (ink))
      (h.getDeletedCanvasContents should contain (ink))
      h.getDeletedCanvasContents.foreach((undeletedInk:MeTLCanvasContent) => {
        val newUndeletedInk = undeletedInk.generateNewIdentity(nextFuncName).adjustTimestamp(ink.timestamp + 2)
        val undeleteMarker = MeTLUndeletedCanvasContent(undeletedInk.server,undeletedInk.author,undeletedInk.timestamp + 1,undeletedInk.target,undeletedInk.privacy,undeletedInk.slide,nextFuncName,"ink",ink.identity,newUndeletedInk.identity)
        h.addStanza(newUndeletedInk)
        h.addStanza(undeleteMarker)
        val nh = h.filter(c => true)
        val mh = new History("merged").merge(nh)
        (mh.getCanvasContents should not contain (ink))
        (mh.getDeletedCanvasContents should contain (ink))
        (mh.getCanvasContents should contain (newUndeletedInk))
        (mh.getUndeletedCanvasContents should contain (undeleteMarker))
      })
    }
	}
}
{'fraction_non_alphanumeric': 0.11675859142978362, 'fraction_numerical': 0.007636826474331778, 'mean_word_length': 4.004670912951168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '130573', 'n_tokens_mistral': 4051, 'n_tokens_neox': 3991, 'n_words': 731}