< Summary

Class:CoordinateUtils
Assembly:CoordinateUtils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Utils/CoordinateUtils.cs
Covered lines:7
Uncovered lines:6
Coverable lines:13
Total lines:49
Line coverage:53.8% (7 of 13)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
IsCoordinateInRange(...)0%20400%
GetTextCoordinates(...)0%4.594066.67%
HasValidTextCoordinates(...)0%110100%
ParseCoordinatesString(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Utils/CoordinateUtils.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.Events;
 4using UnityEngine.EventSystems;
 5using UnityEngine.Serialization;
 6using System.Collections.Generic;
 7using System.Text.RegularExpressions;
 8
 9public class CoordinateUtils
 10{
 11    public const string COORDINATE_MATCH_REGEX = "[-]?\\d{1,3},[-]?\\d{1,3}";
 12    public const int MAX_X_COORDINATE = 163;
 13    public const int MIN_X_COORDINATE = -150;
 14    public const int MAX_Y_COORDINATE = 158;
 15    public const int MIN_Y_COORDINATE = -150;
 16
 017    public static bool IsCoordinateInRange(int x, int y) { return (x <= MAX_X_COORDINATE && x >= MIN_X_COORDINATE && y <
 18
 19    public static List<string> GetTextCoordinates(string text)
 20    {
 4221        Regex filter = new Regex(COORDINATE_MATCH_REGEX);
 4222        List<string> matchingWords = new List<string>();
 28623        foreach (var item in text.Split(' '))
 24        {
 10125            var match = filter.Match(item.ToString());
 26            int x;
 27            int y;
 10128            if (match.Success)
 29            {
 030                Int32.TryParse(item.ToString().Split(',')[0], out x);
 031                Int32.TryParse(item.ToString().Split(',')[1], out y);
 32
 033                if (IsCoordinateInRange(x, y))
 034                    matchingWords.Add(match.Value);
 35            }
 36        }
 4237        return matchingWords;
 38    }
 39
 40    public static bool HasValidTextCoordinates(string text)
 41    {
 4242        return GetTextCoordinates(text).Count > 0;
 43    }
 44
 45    public static ParcelCoordinates ParseCoordinatesString(string coordinates)
 46    {
 047        return new ParcelCoordinates(Int32.Parse(coordinates.Split(',')[0]), Int32.Parse(coordinates.Split(',')[1]));
 48    }
 49}