This is my component
import React from 'react';
import {
View,
Platform,
StatusBar,
StatusBarStyle,
ColorValue,
} from 'react-native';
import { getStatusBarHeight } from 'react-native-iphone-x-helper';
type CustomStatusBarProps = {
barStyle: StatusBarStyle;
backgroundColor: ColorValue;
};
export function CustomStatusBar({
barStyle,
backgroundColor,
}: CustomStatusBarProps) {
const STATUS_BAR_HEIGHT =
Platform.OS === 'ios' ? getStatusBarHeight() + 20 : 0;
console.log('✅ ~ STATUS_BAR_HEIGHT', STATUS_BAR_HEIGHT);
return (
<View
testID="custom-status-bar"
className={`w-full bg-${String(
backgroundColor,
)} h-[${STATUS_BAR_HEIGHT}]`}
>
<StatusBar
translucent
barStyle={barStyle}
backgroundColor={backgroundColor}
/>
</View>
);
}
This is the results of the runing tests:
`jest --verbose
watchman warning: Recrawled this watch 11 times, most recently because:
MustScanSubDirs UserDroppedTo resolve, please review the information on
https://facebook.github.io/watchman/docs/troubleshooting.html#recrawl
To clear this warning, run:
watchman watch-del '/Users/rodrigodiasdefigueiredo/Desktop/zerelparksharing' ; watchman watch-project '/Users/rodrigodiasdefigueiredo/Desktop/zerelparksharing'
PASS src/components/CustomButton/tests/CustomButton.test.tsx
CustomButton
✓ should render the component (202 ms)
✓ should render the title (2 ms)
✓ should call onpress (2 ms)
PASS src/components/CustomFooter/tests/CustomFooter.test.tsx
CustomFooter
✓ the component rendered (218 ms)
✓ the component rendered (3 ms)
console.log
✅ ~ STATUS_BAR_HEIGHT 40
at log (src/components/CustomStatusBar/index.tsx:22:11)
console.log
✅ ~ STATUS_BAR_HEIGHT 0
at log (src/components/CustomStatusBar/index.tsx:22:11)
console.log
✅ ~ STATUS_BAR_HEIGHT 0
at log (src/components/CustomStatusBar/index.tsx:22:11)
FAIL src/components/CustomStatusBar/tests/CustomStatusBar.test.tsx
CustomStatusBar
✓ should render the component (104 ms)
✓ should the platform be ios (2 ms)
✓ should the platform be android
✕ should render the component with the height 40 for IOS (3 ms)
✕ should render the component with the height 0 for Android (2 ms)
● CustomStatusBar › should render the component with the height 40 for IOS
expect(received).toBe(expected) // Object.is equality
Expected: 40
Received: undefined
39 | );
40 | const customStatusBar = getByTestId('custom-status-bar');
> 41 | expect(customStatusBar.props.style[0].height).toBe(40);
| ^
42 | });
43 |
44 | it('should render the component with the height 0 for Android', () => {
at Object.toBe (src/components/CustomStatusBar/__tests__/CustomStatusBar.test.tsx:41:51)
● CustomStatusBar › should render the component with the height 0 for Android
expect(received).toBe(expected) // Object.is equality
Expected: 0
Received: undefined
50 | );
51 | const customStatusBar = getByTestId('custom-status-bar');
> 52 | expect(customStatusBar.props.style[0].height).toBe(0);
| ^
53 | });
54 | });
55 |
at Object.toBe (src/components/CustomStatusBar/__tests__/CustomStatusBar.test.tsx:52:51)
----------------------------|---------|----------|---------|---------|-------------------
File
% Stmts
% Branch
% Funcs
% Lines
Uncovered Line #s
All files
7.03
4.34
8.88
7.14
components/CustomButton
100
100
100
100
index.tsx
100
100
100
100
components/CustomFooter
100
100
100
100
index.tsx
100
100
100
100
components/CustomStatusBar
100
100
100
100
index.tsx
100
100
100
100
components/CustomToast
0
0
0
0
index.tsx
0
0
0
0
12-64
components/OpenDoorModal
0
100
0
0
index.tsx
0
100
0
0
17-62
screens/Home
0
0
0
0
index.tsx
0
0
0
0
11-91
screens/Login
0
100
0
0
index.tsx
0
100
0
0
9-13
screens/Menu
0
100
0
0
index.tsx
0
100
0
0
4-5
screens/MyAccess
0
0
0
0
index.tsx
0
0
0
0
5-16
screens/OnBoarding
0
0
0
0
index.tsx
0
0
0
0
24-180
slides.ts
0
0
0
0
screens/Vehicles
0
100
0
0
index.tsx
0
100
0
0
4-5
screens/Wallet
0
100
0
0
index.tsx
0
100
0
0
4-5
slices/counter
0
100
0
0
counterSlice.ts
0
100
0
0
9-34
----------------------------
---------
----------
---------
---------
-------------------
Test Suites: 1 failed, 2 passed, 3 total
Tests: 2 failed, 8 passed, 10 total
Snapshots: 0 total
Time: 2.343 s
Ran all test suites.`
I'm trying to test the height of the statusbar on both platforms IOS and Android to get 100 on test coverage.`
you need to mock your platform & getStatusBarHeight before expect 40.
Platform.OS = 'ios'
jest.mock('react-native-iphone-x-helper', () => {
return {
getStatusBarHeight: jest.fn().mockReturnValue(20)
}
})
expect(STYLE).toBe(40)
Related
I would like to create bins to get histogram with totals and percentage, e.g. starting from 0.
If possible to set the minimum and maximum value in the bins ( in my case value min=0 and max=20 )
Input file
8 5
10 1
11 4
12 4
12 4
13 5
16 7
18 9
16 9
17 7
18 5
19 5
20 1
21 7
output desired
0 0 0.0%
0 - 2 0 0.0%
2 - 4 0 0.0%
4 - 6 0 0.0%
6 - 8 0 0.0%
8 - 10 5 6.8%
10 - 12 5 6.8%
12 - 14 13 17.8%
14 - 16 0 0.0%
16 - 18 23 31.5%
18 - 20 19 26.0%
> 20 8 11.0%
---------------------
Total: 73
I use this code from Mr Ed Morton, it works perfectly but the percentage is missed.
awk 'BEGIN { delta = (delta == "" ? 2 : delta) }
{
bucketNr = int(($0+delta) / delta)
cnt[bucketNr]++
numBuckets = (numBuckets > bucketNr ? numBuckets : bucketNr)
}
END {
for (bucketNr=1; bucketNr<=numBuckets; bucketNr++) {
end = beg + delta
printf "%0.1f %0.1f %d\n", beg, end, cnt[bucketNr]
beg = end
}
}' file
Thanks in advance
Your expected output doesn't seem to correspond to your sample input data, but try this variation of that awk code in your question (Intended to be put in an executable file to run as a script, not a a one-liner due to size):
#!/usr/bin/awk -f
BEGIN { delta = (delta == "" ? 2 : delta) }
{
bucketNr = int(($0+delta) / delta)
cnt[bucketNr]++
max[bucketNr] = max[bucketNr] < $2 ? $2 : max[bucketNr]
sum += $2
numBuckets = (numBuckets > bucketNr ? numBuckets : bucketNr)
}
END {
for (bucketNr=1; bucketNr<=numBuckets; bucketNr++) {
end = beg + delta
printf "%d-%d %d %.1f\n", beg, end, max[bucketNr],
(cnt[bucketNr] / NR) * 100
beg = end
}
print "-------------"
print "Total " sum
}
It adds tracking the maximum of the second column for each bin the first column falls in, and prints out a percentage instead of a count of how many rows were in each bin. Plus some tweaks to the output format to better match your desired output.
I would like to synchronize colors and fonts between two different instances of IAR's IDE. I know there is no way to export using the IDE itself, but are there configuration files that can be copied to achieve the same result?
I found the file that contains the configuration in XML format:
C:\users\USER_NAME\AppData\Roaming\IAR Embedded Workbench\IarIde.xml
This is the relevant section:
<TextEditor>
<Font0>_ 0 400 0 16777215 0</Font0>
<Font1>_ 0 700 0 16711935 0</Font1>
<Font2>_ 0 400 0 32896 0</Font2>
<Font3>_ 0 400 0 16776960 0</Font3>
<Font4>_ 0 400 0 255 0</Font4>
<Font5>_ 0 400 0 38400 0</Font5>
<Font6>_ 0 400 0 0 0</Font6>
<Font7>_ 0 400 0 0 0</Font7>
<Font8>_ 0 400 0 0 0</Font8>
<Font9>_ 0 400 255 65280 0</Font9>
<Font10>_ 0 400 255 65280 0</Font10>
<Font11>_ 0 400 255 16776960 0</Font11>
<Font12>_ 0 400 255 16776960 0</Font12>
<Font13>_ 0 700 0 0 1</Font13>
<Font14>_ 0 400 255 10485760 0</Font14>
<FontsEx>_ 0 0 0 0 0 0 0 1776411 0</FontsEx>
<Fonts>_ -13 400 3 2 1 49 "Consolas" 15</Fonts>
<IndentSize>_ 2</IndentSize>
<TabSize>_ 2</TabSize>
<AutoIndent>_ 1</AutoIndent>
<BraceIndent>_ 0</BraceIndent>
<BodyIndent>_ 2</BodyIndent>
<LabelIndent>_ 0</LabelIndent>
<RealTabs>_ 0</RealTabs>
<SyntaxHLight>_ 1</SyntaxHLight>
<ShowBookmarks>_ 1</ShowBookmarks>
<ShowLineNumbers>_ 0</ShowLineNumbers>
<ShowFoldsMargin>_ 1</ShowFoldsMargin>
<ScanForChangedFiles>_ 1</ScanForChangedFiles>
<VirtualSpace>_ 0</VirtualSpace>
<CmdLineApp>_ ""</CmdLineApp>
<CmdLineArgs>_ ""</CmdLineArgs>
<DdeApp>_ ""</DdeApp>
<DdeServiceName>_ ""</DdeServiceName>
<FindFlags>_ 6</FindFlags>
<LineBreakUsage>_ 0</LineBreakUsage>
<TrimTrailingBlanks>_ 0</TrimTrailingBlanks>
<UseUserKeyWordFile>_ 0</UseUserKeyWordFile>
<UserKeyWordFile>_ ""</UserKeyWordFile>
<UseCodeTemplates>_ 1</UseCodeTemplates>
<CodeTemplateFile>_ "C:\Users\USER_NAME\AppData\Roaming\IAR Embedded Workbench\CodeTemplates.ENU.txt"</CodeTemplateFile>
<ShowRightMargin>_ 1</ShowRightMargin>
<UsePrinterMargin>_ 0</UsePrinterMargin>
<RightMarginPos>_ 80</RightMarginPos>
<AutoCompletion>_ 1</AutoCompletion>
<AutoDetectEncoding>_ 1</AutoDetectEncoding>
<DefaultEncoding>_ "System"</DefaultEncoding>
<ShowLineBreaks>_ 0</ShowLineBreaks>
<ShowSourceBrowserToolTips>_ 1</ShowSourceBrowserToolTips>
<ShowVisibleWhitespace>_ 0</ShowVisibleWhitespace>
<SyntaxHighlightRubyFiles>_ 1</SyntaxHighlightRubyFiles>
<DdeCmdStr>_ 0</DdeCmdStr>
</TextEditor>
Hey I'm trying to find the distance between records in a text file. I'm trying to do it using awk.
An example input is:
1 2 1 4 yes
2 3 2 2 no
1 1 1 5 yes
4 2 4 0 no
5 1 0 1 no
I want to find the distance between each of the numerical values. I'm doing this by subtracting the values and then squaring the answer. I have tried the following code below but all the distances are simply 0. Any help would be appreciated.
BEGIN {recs = 0; fieldnum = 5;}
{
recs++;
for(i=1;i<=NF;i++) {data[recs,i] = $i;}
}
END {
for(r=1;r<=recs;r++) {
for(f=1;f<fieldnum;f++) {
##find distances
for(t=1;t<=recs;t++) {
distance[r,t]+=((data[r,f] - data[t,f])*(data[r,f] - data[t,f]));
}
}
}
for(r=1;r<=recs;r++) {
for(t=1;t<recs;t++) {
##print distances
printf("distance between %d and %d is %d \n",r,t,distance[r,t]);
}
}
}
No idea what you mean conceptually by the "distance between each of the numerical values" so I can't help you with your algorithm but let's clean up the code to see what that looks like:
$ cat tst.awk
{
for(i=1;i<=NF;i++) {
data[NR,i] = $i
}
}
END {
for(r=1;r<=NR;r++) {
for(f=1;f<NF;f++) {
##find distances
for(t=1;t<=NR;t++) {
delta = data[r,f] - data[t,f]
distance[r,t]+=(delta * delta)
}
}
}
for(r=1;r<=NR;r++) {
for(t=1;t<NR;t++) {
##print distances
printf "distance between %d and %d is %d\n",r,t,distance[r,t]
}
}
}
$
$ awk -f tst.awk file
distance between 1 and 1 is 0
distance between 1 and 2 is 7
distance between 1 and 3 is 2
distance between 1 and 4 is 34
distance between 2 and 1 is 7
distance between 2 and 2 is 0
distance between 2 and 3 is 15
distance between 2 and 4 is 13
distance between 3 and 1 is 2
distance between 3 and 2 is 15
distance between 3 and 3 is 0
distance between 3 and 4 is 44
distance between 4 and 1 is 34
distance between 4 and 2 is 13
distance between 4 and 3 is 44
distance between 4 and 4 is 0
distance between 5 and 1 is 27
distance between 5 and 2 is 18
distance between 5 and 3 is 33
distance between 5 and 4 is 19
Seems to produce some non-zero output....
I have a file like
Sever Name aad98722RHEL 20120630 075022
CPU
1 sec 10 sec 15 sec 1 min 1 hour
5 8 0 1 19
TX kbits/sec:
interface 10 sec 1 min 10 min 1 hour 1 day
--------- ------ ----- ------ ------ -----
eth0 32 33 39 40 33
eth1 6 186 321 199 18
eth2 0 0 0 0 0
mgt0 0 0 0 0 0
RX kbits/sec:
interface 10 sec 1 min 10 min 1 hour 1 day
--------- ------ ----- ------ ------ -----
eth0 19 19 25 26 23
eth1 9 26 40 28 10
eth2 0 0 0 0 0
mgt0 0 0 0 0 0
Total memory usage: 1412916 kB
Resident set size : 1256360 kB
Heap usage : 1368212 kB
Stack usage : 84 kB
Library size : 16316 kB
What I would like to produce is
aad98722RHE 20120630 075022 CPU 5 8 0 1 19
aad98722RHE 20120630 075022 TX kbits/sec: 32 33 39 40 33 6 186 321 199 18 0 0 0 0 0 0 0 0 0 0
aad98722RHE 20120630 075022 RX kbits/sec: 19 19 25 26 23 9 26 40 28 10 0 0 0 0 0 0 0 0 0 0
aad98722RHE 20120630 075022 Total memory usage: 1412916 kB Resident set size : 1256360 kB Heap usage : 1368212 kB Stack usage : 84 kB Library size : 16316 kB
Can this be done in Awk/Sed and how?
Perhaps it not better solution, but it work.
file: a.awk:
function print_cpu( server_name, cpu )
{
while ( $0 !~ cpu )
{
getline
}
getline
getline
printf "%s %s ", server_name, cpu
for ( i = 1; i < NF + 1; i++ )
{
printf "%s ", $i
}
printf "\n"
}
function print_rx_or_tx( server_name, rx_or_tx )
{
while ( $0 !~ rx_or_tx )
{
getline
}
getline
getline
getline
printf "%s %s ", server_name, rx_or_tx
while ( $0 != "" )
{
getline
for ( i = 2; i < NF; i++ )
{
printf "%s ", $i
}
}
printf "\n"
}
function print_stuff( server_name )
{
while ( $0 == "" )
{
getline
}
printf "%s ", server_name
while ( $0 != "" )
{
printf "%s ", $0
if ( getline <= 0 )
{
break
}
}
printf "\n"
}
BEGIN { server = "Server Name"; cpu = "CPU"; tx = "TX kbits/sec:"; rx = "RX kbits/sec:" }
server { server_name = $3 " " $4 " " $5 }
! server
{
print_cpu( server_name, cpu )
print_rx_or_tx( server_name, tx )
print_rx_or_tx( server_name, rx )
print_stuff( server_name )
}
run: awk -f a.awk your_input_file
One way using perl:
Assuming infile has content of your question and next content in script.pl:
use warnings;
use strict;
my ($header, $newlines, $trans, #nums);
## Read input in paragraph mode.
local $/ = qq||;
while ( my $par = <> ) {
chomp $par;
## Save data of the header.
if ( $. == 1 ) {
my #header = $par =~ m/\ASer?ver\s+Name\s+(\S+)\s+(\S+)\s+(\S+)\s*\Z/s;
last unless #header;
$header = join qq| |, #header;
next;
}
## Number of '\n' in each paragraph (number of lines minus one).
$newlines = $par =~ tr/\n/\n/;
## Three lines, the CPU info. Extract what I need and print.
if ( $newlines == 2 ) {
printf qq|%s %s %s\n|, $header, $par =~ m/\A([^\n]+).*\n([^\n]+)\Z/s;
next;
}
## Transmission string.
if ( $newlines == 0 ) {
$trans = $par;
next;
}
## Transmission info. Extract numbers and print.
if ( $newlines == 5 ) {
my #lines = split /\n/, $par;
for my $i ( 0 .. $#lines ) {
my #f = split /\s+/, $lines[ $i ];
if ( grep { m/\D/ } #f[ 1 .. $#f ] ) {
next;
}
else {
push #nums, #f[ 1 .. $#f ];
}
}
printf qq|%s %s\n|, $header, join qq| |, #nums;
#nums = ();
}
## Resume info. Extract and print.
if ( $newlines == 4 ) {
$par =~ s/\n/\t/gs;
printf qq|%s %s\n|, $header, $par;
}
}
Run it like:
perl script.pl infile
With following output:
aad98722RHEL 20120630 075022 CPU 5 8 0 1 19
aad98722RHEL 20120630 075022 32 33 39 40 33 6 186 321 199 18 0 0 0 0 0 0 0 0 0 0
aad98722RHEL 20120630 075022 19 19 25 26 23 9 26 40 28 10 0 0 0 0 0 0 0 0 0 0
aad98722RHEL 20120630 075022 Total memory usage: 1412916 kB Resident set size : 1256360 kB Heap usage : 1368212 kB Stack usage : 84 kB Library size : 16316 kB
I would really appreciate some help. I spent almost the whole morning on it.
I have a data of structure field 1 to 16 as follows
4572 1307084940 RDCSWE 2006 1 5 0.28125 0.5 0.125 0.09375 0 0 0 0 0 0
4573 1307101627 RDCSWE 2006 1 5 0.6875 0.125 0.1875 0 0 0 0 0 0 0
4574 1307101642 RDCSWE 2006 1 5 0.5625 0.25 0.03125 0.15625 0 0 0 0 0 0
4575 1307101662 RDCSWE 2006 1 5 0.53125 0.25 0.1875 0.03125 0 0 0 0 0 0
4576 1307127329 RDCSWE 2006 1 5 0.4375 0.34375 0.09375 0.125 0 0 0 0 0 0
From field 7 to 10 I need a test on the elements (ranging fro 0-1) and the field number.
i.e. for every record, check the fields 7-10 for maximum value,
if found and its in field 7 print $0, $6-4
if found and its in field 8 print $0, $6-3
if found and its in field 9 print $0, $6-2
if found and its in field 10 print $0, $6-1
I'll be so grateful for the help. Thank you in advance
Edit (by belisarius)
Just transcripting a comment from #Tumi2002 (author)
Sorry, my 6th field (i.e. $6) has values 1-5.
I am trying to reclassify records where field 6=5 back into 1-4 classes in the same fieid).
So that instead of 5 classes I have 4.
Awk '$6==5
{for i=7; i<11; i++)
if ($i==max) && NF==7) print $0,$6-4;
if ($i==max) && NF==8) print $0,$6-3;
if ($i==max) && NF==9) print $0,$6-2;
if ($i==max) && NF==10) print $0,$6-1
I am struggling with the syntax in awk
{
max=0; maxindex=0;
for (i=7; i<=10; i++)
{
if ($i>max){
maxindex=i;
max=$i;
# print i;
}
}
if (maxindex > 0){
print $6-11+maxindex;
}
}
Running at ideone
Output for your example data:
2
1
1
1
1
Edit
Modified answering your comment:
($6 == 5){
max=0; maxindex=0;
for (i=7; i<=10; i++)
{
if ($i>max){
maxindex=i;
max=$i;
# print i;
}
}
if (maxindex > 0){
print $0,"-->",$6-11+maxindex;
}
}
Output:
4572 1307084940 RDCSWE 2006 1 5 0.28125 0.5 0.125 0.09375 0 0 0 0 0 0 --> 2
4573 1307101627 RDCSWE 2006 1 5 0.6875 0.125 0.1875 0 0 0 0 0 0 0 --> 1
4574 1307101642 RDCSWE 2006 1 5 0.5625 0.25 0.03125 0.15625 0 0 0 0 0 0 --> 1
4575 1307101662 RDCSWE 2006 1 5 0.53125 0.25 0.1875 0.03125 0 0 0 0 0 0 --> 1
4576 1307127329 RDCSWE 2006 1 5 0.4375 0.34375 0.09375 0.125 0 0 0 0 0 0 --> 1
Running at ideone here
First of all, thanks for belisarius for pointing to ideone.
My (updated) solution is working correctly now:
# max value in an array, copied verbatim from the gawk manual (credit)
function maxelt(vec, i, ret)
{
for (i in vec) {
if (ret == "" || vec[i] > ret)
ret = vec[i]
}
return ret
}
# Load all fields of each record into nums.
{
delete nums
for(i = 7; i <= 10; i++)
{ nums[NR, i] = $i }
### DEBUG print NR, maxelt(nums)
if ( $7 == maxelt(nums) ) { print $0, ($6-4) }
if ( $8 == maxelt(nums) ) { print $0, ($6-3) }
if ( $9 == maxelt(nums) ) { print $0, ($6-2) }
if ( $10 == maxelt(nums) ) { print $0, ($6-1) }
}
HTH