コード例 #1
0
        public static double CompareV2(this MagickImage self, MagickImage oldImg, ErrorMetric errorMetric, out MagickImage imgWithDifferences)
        {
            // Check if both images have the same size:
            bool isNewImageSameSizeAsOldImage = oldImg.Width == self.Width && oldImg.Height == self.Height;

            if (!isNewImageSameSizeAsOldImage)
            {
                var  diffSizesWarn = $"Different sizes: OldImage=({oldImg.Width}X{oldImg.Height}) but NewImage=({self.Width}X{self.Height})";
                bool isNewImageAspectRatioSameAsOldImage = self.GetAspectRatio() == oldImg.GetAspectRatio();
                if (isNewImageAspectRatioSameAsOldImage)
                {
                    Log.w(diffSizesWarn);
                    // If aspect ratio matches, resize both images to same size:
                    var minWidth  = Math.Min(oldImg.Width, self.Width);
                    var minHeight = Math.Min(oldImg.Height, self.Height);
                    oldImg.Resize(minWidth, minHeight);
                    self.Resize(minWidth, minHeight);
                }
                else     // Missmatch in image sizes cant be fixed, abort:
                {
                    throw new ArgumentException("Can't compare! " + diffSizesWarn);
                }
            }
            AssertV2.AreEqual(oldImg.Width, self.Width, "RegressionImage.Width");
            AssertV2.AreEqual(oldImg.Height, self.Height, "RegressionImage.Height");
            //return oldImg.Compare(self, out imgWithDifferences);
            imgWithDifferences = new MagickImage();
            return(oldImg.Compare(self, new CompareSettings()
            {
                Metric = errorMetric
            }, imgWithDifferences));
        }
コード例 #2
0
            public static MergeConflict ToMergeConflict(JProperty prop)
            {
                var res = new MergeConflict();

                res.fieldName = prop.Name;
                if (prop.Value is JObject o)
                {
                    var properties = o.Properties();
                    if (IsArray(properties.First()))
                    {
                        res.specialType = MergeConflict.SPECIAL_TYPE_ARRAY;
                        properties      = properties.Skip(1);
                    }
                    res.conflicts = properties.Map(ToMergeConflict);
                }
                else if (prop.Value is JArray oldAndNewValue)
                {
                    AssertV2.AreEqual(2, oldAndNewValue.Count);
                    res.oldValue = oldAndNewValue[0];
                    res.newValue = oldAndNewValue[1];
                }
                else
                {
                    throw new NotImplementedException("Unhandled type " + prop.Value.GetType() + ":\n" + prop.Value.ToPrettyString());
                }
                return(res);
            }
コード例 #3
0
 private static IEnumerable <JToken> GetFilteredDiff(JToken diffToExpectedState, Func <JToken, bool> filterAcceptableDiffs)
 {
     return(diffToExpectedState.Children().Skip(1).Filter(problem => {
         AssertV2.AreEqual(1, problem.Count(), "The diff contained not exactly one element");
         return filterAcceptableDiffs(problem.First());
     }));
 }
コード例 #4
0
        public static Texture2D ToTexture2D(this ImageResult self)
        {
            AssertV2.AreEqual(8, self.BitsPerChannel);
            Texture2D tex = new Texture2D(self.Width, self.Height, TextureFormat.RGBA32, false);

            tex.LoadRawTextureData(self.Data);
            tex.Apply();
            return(tex);
        }
コード例 #5
0
        private async Task <bool> RunInternetCheck()
        {
            var newState = await RestFactory.instance.HasInternet();

            await SetHasInet(newState);

            AssertV2.AreEqual(HasInet, newState);
            return(HasInet);
        }
コード例 #6
0
 public static Vector3[] GetWorldCornersV2(this RectTransform self, Vector3[] cache = null)
 {
     if (cache == null)
     {
         cache = new Vector3[4];
     }
     AssertV2.AreEqual(4, cache.Length);
     self.GetWorldCorners(cache);
     return(cache);
 }
コード例 #7
0
 public static FileEntry GetChild(this DirectoryEntry self, string fileName, bool sanitize = true)
 {
     fileName.ThrowErrorIfNullOrEmpty("fileName");
     if (sanitize)
     {
         fileName = Sanitize.SanitizeToFileName(fileName);
     }
     AssertV2.AreEqual(fileName, Sanitize.SanitizeToFileName(fileName));
     return(ResolveFilePath(self, fileName));
 }
コード例 #8
0
 public static DirectoryEntry GetChildDir(this DirectoryEntry self, string subDirName, bool sanitize = true)
 {
     subDirName.ThrowErrorIfNullOrEmpty("subDirName");
     if (sanitize)
     {
         subDirName = Sanitize.SanitizeToDirName(subDirName);
     }
     AssertV2.AreEqual(subDirName, Sanitize.SanitizeToDirName(subDirName));
     return(ResolveDirectoryPath(self, subDirName));
 }
コード例 #9
0
 public static UnityWebRequest SetRequestHeaders(this UnityWebRequest self, Headers headersToAdd)
 {
     if (!headersToAdd.IsNullOrEmpty())
     {
         foreach (var h in headersToAdd)
         {
             AssertV2.AreEqual(1, h.Value.Count());
             self.SetRequestHeader(h.Key, h.Value.First());
         }
     }
     return(self);
 }
コード例 #10
0
ファイル: FileExtensions.cs プロジェクト: cs-util-com/cscore
        public static DirectoryInfo GetChildDir(this DirectoryInfo self, string subDirName, bool assertThatChildMustExist = false, bool sanitize = true)
        {
            subDirName.ThrowErrorIfNullOrEmpty("subDirName");
            if (sanitize)
            {
                subDirName = Sanitize.SanitizeToDirName(subDirName);
            }
            AssertV2.AreEqual(subDirName, Sanitize.SanitizeToDirName(subDirName));
            var c = new DirectoryInfo(self.FullPath() + subDirName);

            if (assertThatChildMustExist)
            {
                AssertV2.IsTrue(c.IsNotNullAndExists(), "childFolder '" + subDirName + "' doesnt exist! Path=" + c.FullPath());
            }
            return(c);
        }
コード例 #11
0
ファイル: FileExtensions.cs プロジェクト: cs-util-com/cscore
        public static FileInfo GetChild(this DirectoryInfo self, string fileName, bool assertThatChildMustExist = false, bool sanitize = true)
        {
            fileName.ThrowErrorIfNullOrEmpty("fileName");
            if (sanitize)
            {
                fileName = Sanitize.SanitizeToFileName(fileName);
            }
            AssertV2.AreEqual(fileName, Sanitize.SanitizeToFileName(fileName));
            var c = new FileInfo(self.FullPath() + fileName);

            if (assertThatChildMustExist)
            {
                AssertV2.IsTrue(c.IsNotNullAndExists(), "childFile '" + fileName + "' doesnt exist! Path=" + c.FullPath());
            }
            return(c);
        }
コード例 #12
0
 public static double CompareV2(this MagickImage self, MagickImage oldImg, ErrorMetric errorMetric, out MagickImage imgWithDifferences)
 {
     AssertV2.AreEqual(oldImg.Width, self.Width, "RegressionImage.Width");
     AssertV2.AreEqual(oldImg.Height, self.Height, "RegressionImage.Height");
     // Check if both images have the same size:
     if (oldImg.Width != self.Width || oldImg.Height != self.Height)
     {
         if (self.GetAspectRatio() == oldImg.GetAspectRatio())
         {
             // If aspect ratio matches, resize both images to same size:
             var minWidth  = Math.Min(oldImg.Width, self.Width);
             var minHeight = Math.Min(oldImg.Height, self.Height);
             oldImg.Resize(minWidth, minHeight);
             self.Resize(minWidth, minHeight);
         }
     }
     //return oldImg.Compare(self, out imgWithDifferences);
     imgWithDifferences = new MagickImage();
     return(oldImg.Compare(self, new CompareSettings()
     {
         Metric = errorMetric
     }, imgWithDifferences));
 }
コード例 #13
0
ファイル: ZioExtensions.cs プロジェクト: shoshiiran/cscore
 public static FileEntry GetChild(this DirectoryEntry self, string fileName)
 {
     AssertV2.AreEqual(fileName, EnvironmentV2.SanatizeToFileName(fileName));
     return(ResolveFilePath(self, fileName));
 }
コード例 #14
0
ファイル: ZioExtensions.cs プロジェクト: shoshiiran/cscore
 public static DirectoryEntry GetChildDir(this DirectoryEntry self, string subDirName)
 {
     AssertV2.AreEqual(subDirName, EnvironmentV2.SanatizeToFileName(subDirName));
     return(new DirectoryEntry(self.FileSystem, self.Path / subDirName));
 }
コード例 #15
0
ファイル: ZioExtensions.cs プロジェクト: llorch19/cscore
 public static FileEntry GetChild(this DirectoryEntry self, string fileName)
 {
     AssertV2.AreEqual(fileName, EnvironmentV2.SanatizeToFileName(fileName));
     return(new FileEntry(self.FileSystem, self.Path / fileName));
 }