Skip to content

Commit

Permalink
#85 float.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 2, 2023
1 parent fc87848 commit 3be09d4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
27 changes: 27 additions & 0 deletions help/float.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2021-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -e
set -o pipefail

num=$(cat)
printf '%.8f' "${num}" | sed -e 's/0\+$//' | sed -e 's/\.$//'
6 changes: 3 additions & 3 deletions steps/aggregate-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if [ -e "${ddir}" ]; then
fi

find "${dir}" -name '*.m' | {
declare -i sum=0
sum=0
while IFS= read -r m; do
find "$(dirname "${m}")" -name "$(basename "${m}").*" -type f -print | while IFS= read -r v; do
java=$(echo "${v}" | sed "s|${dir}||" | sed "s|\.m\..*$||")
Expand All @@ -53,10 +53,10 @@ find "${dir}" -name '*.m' | {
printf '%s' "${java}" >> "${csv}"
for a in ${all}; do
if [ -e "${m}.${a}" ]; then
value=$(cat "${m}.${a}")
value=$(cat "${m}.${a}" | "${LOCAL}/help/float.sh")
printf ",%s" "${value}" >> "${csv}"
if [ ! "${value}" = "NaN" ]; then
sum=$((sum + value))
sum=$(echo "${sum} + ${value}" | bc | "${LOCAL}/help/float.sh")
fi
else
printf ',-' >> "${csv}"
Expand Down
9 changes: 5 additions & 4 deletions steps/measure-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ start=$(date +%s%N)
mkdir -p "$(dirname "${javam}")"
metrics=$(find "${LOCAL}/metrics/" -type f -exec basename {} \;)
echo "${metrics}" | {
declare -i sum=0
sum=0
while IFS= read -r m; do
if timeout 30m "metrics/${m}" "${java}" "${javam}"; then
while IFS= read -r t; do
IFS=' ' read -r -ra M <<< "${t}"
echo "${M[1]}" > "${javam}.${M[0]}"
if [ ! "${M[1]}" = "NaN" ]; then
sum=$((sum + M[1]))
value=$(echo "${M[1]}" | "${LOCAL}/help/float.sh")
echo "${value}" > "${javam}.${M[0]}"
if [ ! "${value}" = "NaN" ]; then
sum=$(echo "${sum} + ${value}" | bc | "${LOCAL}/help/float.sh")
fi
done < "${javam}"
else
Expand Down
37 changes: 37 additions & 0 deletions tests/help/test-float.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2021-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -e
set -o pipefail

test "$(echo '.42' | "${LOCAL}/help/float.sh")" = '0.42'
echo "👍🏻 Corrected floating point number"

test "$(echo '254.42' | "${LOCAL}/help/float.sh")" = '254.42'
echo "👍🏻 Corrected longer floating point number"

test "$(echo '256' | "${LOCAL}/help/float.sh")" = '256'
echo "👍🏻 Corrected integer number"

test "$(echo '.000000099' | "${LOCAL}/help/float.sh")" = '0.0000001'
echo "👍🏻 Corrected small precision number"

2 changes: 1 addition & 1 deletion tests/steps/test-aggregate-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ repo="foo/bar test ; "
dir="${TARGET}/measurements/${repo}/a"
mkdir -p "${dir}"
touch "${dir}/Foo.java.m"
echo ".75" > "${dir}/Foo.java.m.nhd"
echo "42" > "${dir}/Foo.java.m.loc"
echo "256" > "${dir}/Foo.java.m.nhd"
msg=$("${LOCAL}/steps/aggregate-repo.sh" "${repo}" 1 1 'loc nhd')
echo "${msg}" | (grep "sum=0" && exit 1 || true)
test -e "${TARGET}/data/${repo}/all.csv"
Expand Down

0 comments on commit 3be09d4

Please sign in to comment.