public override void Check(Submission other) { // Check if this is disabled if (!_submission.Config.CheckContent || !other.Processor.GetCheckTypes().HasFlag(GetType())) { return; } // Create local copies of content to avoid colllisons, and trim it string originalContent = _submission.Content; if (_submission.ContentLength > _submission.Config.CheckContentMaximumLength) { originalContent = originalContent.Substring(0, _submission.Config.CheckContentMaximumLength); } string otherContent = other.Content; if (other.ContentLength > _submission.Config.CheckContentMaximumLength) { otherContent = otherContent.Substring(0, _submission.Config.CheckContentMaximumLength); } double contentComparison = Compare.CalculateSimilarity(originalContent, otherContent); if (contentComparison >= _submission.Config.CheckContentThreshold) { Flag.AddSimilarSubmission(other, contentComparison, string.Empty); } }
public void CalculateSimilarityShort() { const string String1 = "Hello"; const string String2 = "jacuzzis"; Assert.Equal(1.0, Compare.CalculateSimilarity(String1, String1)); Assert.Equal(0.0, Compare.CalculateSimilarity(String1, String2)); }
public void CalculateSimilarityBigMany() { const int numChecks = 2; for (int i = 0; i < numChecks; i++) { SetNLipsumSeed(10001 + i); string large1 = LipsumGenerator.Generate(16); SetNLipsumSeed(84301 + i); string large2 = LipsumGenerator.Generate(16); Assert.NotEqual(1.0, Compare.CalculateSimilarity(large1, large2)); } }
public void CalculateSimilarityShortMany() { const int numChecks = 10000; const int seed = 40392; XmlDocument document = new XmlDocument(); // Load document using helper function document.Load(TestHelper.GetResourceContentPath("Test-English-Words.xml")); var node = document.SelectSingleNode("words"); string[] words = node.InnerText.Split(new [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < words.Length; i++) { words[i] = words[i].Trim(); } System.Random rand = new Random(seed); for (int i = 0; i < numChecks; i++) { for (int j = 0; j < words.Length; j++) { int firstIndex, secondIndex; while (true) { firstIndex = rand.Next(words.Length); secondIndex = rand.Next(words.Length); if (firstIndex != secondIndex) { break; } } string first = words[firstIndex], second = words[secondIndex]; Assert.NotEqual(first, second); Assert.NotEqual(1.0, Compare.CalculateSimilarity(first, second)); } } }
public override void Check(Submission other) { // Check if we're doing this check if (!_submission.Config.CheckFileName || !other.Processor.GetCheckTypes().HasFlag(GetType())) { return; } // Check if the other has the same capability // other.Processor.GetCheckTypes() // TODO : Remove copy parts (1) / copy // TODO: 2018.2 // Calculate difference double fileNameComparison = Compare.CalculateSimilarity(_submission.FileName, other.FileName); // Evaluate check if (fileNameComparison > _submission.Config.CheckFileNameThreshold) { Flag.AddSimilarSubmission(other, fileNameComparison, other.FileName); } }