Best Python code snippet using localstack_python
bootstrap-table-multiple-sort.js
Source:bootstrap-table-multiple-sort.js
...84 sortName: name,85 sortOrder: order86 };87 });88 var sorted_fields = fields.sort();89 for (var i = 0; i < fields.length - 1; i++) {90 if (sorted_fields[i + 1] == sorted_fields[i]) {91 results.push(sorted_fields[i]);92 }93 }94 if (results.length > 0) {95 if ($alert.length === 0) {96 $alert = '<div class="alert alert-danger" role="alert"><strong>' + that.options.formatDuplicateAlertTitle() + '</strong> ' + that.options.formatDuplicateAlertDescription() + '</div>';97 $($alert).insertBefore(that.$sortModal.find('.bars'));98 }99 } else {100 if ($alert.length === 1) {101 $($alert).remove();102 }103 that.$sortModal.modal('hide');104 that.options.sortName = '';105 if (that.options.sidePagination === 'server') {106 that.options.queryParams = function(params) {107 params.multiSort = that.options.sortPriority;108 return params;109 };110 that.initServer(that.options.silentSort);111 return;112 }113 that.onMultipleSort();114 }115 });116 if (that.options.sortPriority === null || that.options.sortPriority.length === 0) {117 if (that.options.sortName) {118 that.options.sortPriority = [{119 sortName: that.options.sortName,120 sortOrder: that.options.sortOrder121 }];122 }123 }124 if (that.options.sortPriority !== null && that.options.sortPriority.length > 0) {125 if ($rows.length < that.options.sortPriority.length && typeof that.options.sortPriority === 'object') {126 for (var i = 0; i < that.options.sortPriority.length; i++) {127 that.addLevel(i, that.options.sortPriority[i]);128 }129 }130 } else {131 that.addLevel(0);132 }133 that.setButtonStates();134 }135 };136 $.extend($.fn.bootstrapTable.defaults, {137 showMultiSort: false,138 sortPriority: null,139 onMultipleSort: function() {140 return false;141 }142 });143 $.extend($.fn.bootstrapTable.defaults.icons, {144 sort: 'glyphicon-sort',145 plus: 'glyphicon-plus',146 minus: 'glyphicon-minus'147 });148 $.extend($.fn.bootstrapTable.Constructor.EVENTS, {149 'multiple-sort.bs.table': 'onMultipleSort'150 });151 $.extend($.fn.bootstrapTable.locales, {152 formatMultipleSort: function() {153 return 'Multiple Sort';154 },155 formatAddLevel: function() {156 return 'Add Level';157 },158 formatDeleteLevel: function() {159 return 'Delete Level';160 },161 formatColumn: function() {162 return 'Column';163 },164 formatOrder: function() {165 return 'Order';166 },167 formatSortBy: function() {168 return 'Sort by';169 },170 formatThenBy: function() {171 return 'Then by';172 },173 formatSort: function() {174 return 'Sort';175 },176 formatCancel: function() {177 return 'Cancel';178 },179 formatDuplicateAlertTitle: function() {180 return 'Duplicate(s) detected!';181 },182 formatDuplicateAlertDescription: function() {183 return 'Please remove or change any duplicate column.';184 },185 formatSortOrders: function() {186 return {187 asc: 'Ascending',188 desc: 'Descending'189 };190 }191 });192 $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);193 var BootstrapTable = $.fn.bootstrapTable.Constructor,194 _initToolbar = BootstrapTable.prototype.initToolbar;195 BootstrapTable.prototype.initToolbar = function() {196 this.showToolbar = true;197 var that = this,198 sortModalId = '#sortModal_' + this.$el.attr('id');199 this.$sortModal = $(sortModalId);200 _initToolbar.apply(this, Array.prototype.slice.apply(arguments));201 if (this.options.showMultiSort) {202 var $btnGroup = this.$toolbar.find('>.btn-group').first(),203 $multiSortBtn = this.$toolbar.find('div.multi-sort');204 if (!$multiSortBtn.length) {205 $multiSortBtn = ' <button class="multi-sort btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" data-toggle="modal" data-target="' + sortModalId + '" title="' + this.options.formatMultipleSort() + '">';206 $multiSortBtn += ' <i class="' + this.options.iconsPrefix + ' ' + this.options.icons.sort + '"></i>';207 $multiSortBtn += '</button>';208 $btnGroup.append($multiSortBtn);209 showSortModal(that);210 }211 this.$el.on('sort.bs.table', function() {212 isSingleSort = true;213 });214 this.$el.on('multiple-sort.bs.table', function() {215 isSingleSort = false;216 });217 this.$el.on('load-success.bs.table', function() {218 if (!isSingleSort && that.options.sortPriority !== null && typeof that.options.sortPriority === 'object' && that.options.sidePagination !== 'server') {219 that.onMultipleSort();220 }221 });222 this.$el.on('column-switch.bs.table', function(field, checked) {223 for (var i = 0; i < that.options.sortPriority.length; i++) {224 if (that.options.sortPriority[i].sortName === checked) {225 that.options.sortPriority.splice(i, 1);226 }227 }228 that.assignSortableArrows();229 that.$sortModal.remove();230 showSortModal(that);231 });232 this.$el.on('reset-view.bs.table', function() {233 if (!isSingleSort && that.options.sortPriority !== null && typeof that.options.sortPriority === 'object') {234 that.assignSortableArrows();235 }236 });237 }238 };239 BootstrapTable.prototype.onMultipleSort = function() {240 var that = this;241 var cmp = function(x, y) {242 return x > y ? 1 : x < y ? -1 : 0;243 };244 var arrayCmp = function(a, b) {245 var arr1 = [],246 arr2 = [];247 for (var i = 0; i < that.options.sortPriority.length; i++) {248 var order = that.options.sortPriority[i].sortOrder === 'desc' ? -1 : 1,249 aa = a[that.options.sortPriority[i].sortName],250 bb = b[that.options.sortPriority[i].sortName];251 if (aa === undefined || aa === null) {252 aa = '';253 }254 if (bb === undefined || bb === null) {255 bb = '';256 }257 if ($.isNumeric(aa) && $.isNumeric(bb)) {258 aa = parseFloat(aa);259 bb = parseFloat(bb);260 }261 if (typeof aa !== 'string') {262 aa = aa.toString();263 }264 arr1.push(265 order * cmp(aa, bb));266 arr2.push(267 order * cmp(bb, aa));268 }269 return cmp(arr1, arr2);270 };271 this.data.sort(function(a, b) {272 return arrayCmp(a, b);273 });274 this.initBody();275 this.assignSortableArrows();276 this.trigger('multiple-sort');277 };278 BootstrapTable.prototype.addLevel = function(index, sortPriority) {279 var text = index === 0 ? this.options.formatSortBy() : this.options.formatThenBy();280 this.$sortModal.find('tbody')281 .append($('<tr>')282 .append($('<td>').text(text))283 .append($('<td>').append($('<select class="form-control multi-sort-name">')))284 .append($('<td>').append($('<select class="form-control multi-sort-order">')))285 );...
summaryTableHeader.js
Source:summaryTableHeader.js
1const React = require('react');2function getSortDetails(sortKey, activeSort) {3 let newSort = { sortKey, order: 'desc' };4 let sortClass = '';5 if (activeSort && activeSort.sortKey === sortKey) {6 sortClass = 'sorted';7 if (activeSort.order === 'desc') {8 sortClass += '-desc';9 newSort.order = 'asc';10 } else {11 if (sortKey !== 'file') {12 newSort = { sortKey: 'file', order: 'desc' };13 }14 }15 }16 return {17 newSort,18 sortClass19 };20}21function SummaryTableHeaderCell({ name, onSort, sortKey, activeSort }) {22 const { newSort, sortClass } = getSortDetails(sortKey, activeSort);23 return (24 <th25 className={'sortable headercell ' + sortClass}26 onClick={() => onSort(newSort)}27 >28 {name}29 <span className="sorter" />30 </th>31 );32}33function FileHeaderCell({ onSort, activeSort }) {34 const { newSort, sortClass } = getSortDetails('file', activeSort);35 return (36 <th37 className={'sortable file ' + sortClass}38 onClick={() => onSort(newSort)}39 >40 File41 <span className="sorter" />42 </th>43 );44}45function SubHeadings({ sortKeyPrefix, onSort, activeSort }) {46 return (47 <>48 <SummaryTableHeaderCell49 name="%"50 onSort={onSort}51 sortKey={sortKeyPrefix + '.pct'}52 activeSort={activeSort}53 />54 <th className="headercell"></th>55 <SummaryTableHeaderCell56 name="Covered"57 onSort={onSort}58 sortKey={sortKeyPrefix + '.covered'}59 activeSort={activeSort}60 />61 <SummaryTableHeaderCell62 name="Missed"63 onSort={onSort}64 sortKey={sortKeyPrefix + '.missed'}65 activeSort={activeSort}66 />67 <SummaryTableHeaderCell68 name="Total"69 onSort={onSort}70 sortKey={sortKeyPrefix + '.total'}71 activeSort={activeSort}72 />73 </>74 );75}76module.exports = function SummaryTableHeader({77 onSort,78 activeSort,79 metricsToShow80}) {81 return (82 <thead>83 <tr className="topheading">84 <th></th>85 {metricsToShow.statements && <th colSpan={4}>Statements</th>}86 {metricsToShow.branches && <th colSpan={4}>Branches</th>}87 {metricsToShow.functions && <th colSpan={4}>Functions</th>}88 {metricsToShow.lines && <th colSpan={4}>Lines</th>}89 </tr>90 <tr className="subheading">91 <FileHeaderCell onSort={onSort} activeSort={activeSort} />92 {metricsToShow.statements && (93 <SubHeadings94 sortKeyPrefix="statements"95 onSort={onSort}96 activeSort={activeSort}97 />98 )}99 {metricsToShow.branches && (100 <SubHeadings101 sortKeyPrefix="branches"102 onSort={onSort}103 activeSort={activeSort}104 />105 )}106 {metricsToShow.functions && (107 <SubHeadings108 sortKeyPrefix="functions"109 onSort={onSort}110 activeSort={activeSort}111 />112 )}113 {metricsToShow.lines && (114 <SubHeadings115 sortKeyPrefix="lines"116 onSort={onSort}117 activeSort={activeSort}118 />119 )}120 </tr>121 </thead>122 );...
sort.ts
Source:sort.ts
1import { MongoDriverError } from './error';2/** @public */3export type SortDirection =4 | 15 | -16 | 'asc'7 | 'desc'8 | 'ascending'9 | 'descending'10 | { $meta: string };11/** @public */12export type Sort =13 | string14 | Exclude<SortDirection, { $meta: string }>15 | string[]16 | { [key: string]: SortDirection }17 | Map<string, SortDirection>18 | [string, SortDirection][]19 | [string, SortDirection];20/** Below stricter types were created for sort that correspond with type that the cmd takes */21/** @internal */22export type SortDirectionForCmd = 1 | -1 | { $meta: string };23/** @internal */24export type SortForCmd = Map<string, SortDirectionForCmd>;25/** @internal */26type SortPairForCmd = [string, SortDirectionForCmd];27/** @internal */28function prepareDirection(direction: any = 1): SortDirectionForCmd {29 const value = `${direction}`.toLowerCase();30 if (isMeta(direction)) return direction;31 switch (value) {32 case 'ascending':33 case 'asc':34 case '1':35 return 1;36 case 'descending':37 case 'desc':38 case '-1':39 return -1;40 default:41 throw new MongoDriverError(`Invalid sort direction: ${JSON.stringify(direction)}`);42 }43}44/** @internal */45function isMeta(t: SortDirection): t is { $meta: string } {46 return typeof t === 'object' && t !== null && '$meta' in t && typeof t.$meta === 'string';47}48/** @internal */49function isPair(t: Sort): t is [string, SortDirection] {50 if (Array.isArray(t) && t.length === 2) {51 try {52 prepareDirection(t[1]);53 return true;54 } catch (e) {55 return false;56 }57 }58 return false;59}60function isDeep(t: Sort): t is [string, SortDirection][] {61 return Array.isArray(t) && Array.isArray(t[0]);62}63function isMap(t: Sort): t is Map<string, SortDirection> {64 return t instanceof Map && t.size > 0;65}66/** @internal */67function pairToMap(v: [string, SortDirection]): SortForCmd {68 return new Map([[`${v[0]}`, prepareDirection([v[1]])]]);69}70/** @internal */71function deepToMap(t: [string, SortDirection][]): SortForCmd {72 const sortEntries: SortPairForCmd[] = t.map(([k, v]) => [`${k}`, prepareDirection(v)]);73 return new Map(sortEntries);74}75/** @internal */76function stringsToMap(t: string[]): SortForCmd {77 const sortEntries: SortPairForCmd[] = t.map(key => [`${key}`, 1]);78 return new Map(sortEntries);79}80/** @internal */81function objectToMap(t: { [key: string]: SortDirection }): SortForCmd {82 const sortEntries: SortPairForCmd[] = Object.entries(t).map(([k, v]) => [83 `${k}`,84 prepareDirection(v)85 ]);86 return new Map(sortEntries);87}88/** @internal */89function mapToMap(t: Map<string, SortDirection>): SortForCmd {90 const sortEntries: SortPairForCmd[] = Array.from(t).map(([k, v]) => [91 `${k}`,92 prepareDirection(v)93 ]);94 return new Map(sortEntries);95}96/** converts a Sort type into a type that is valid for the server (SortForCmd) */97export function formatSort(98 sort: Sort | undefined,99 direction?: SortDirection100): SortForCmd | undefined {101 if (sort == null) return undefined;102 if (typeof sort === 'string') return new Map([[sort, prepareDirection(direction)]]);103 if (typeof sort !== 'object') {104 throw new MongoDriverError(`Invalid sort format: ${JSON.stringify(sort)}`);105 }106 if (!Array.isArray(sort)) {107 return isMap(sort) ? mapToMap(sort) : Object.keys(sort).length ? objectToMap(sort) : undefined;108 }109 if (!sort.length) return undefined;110 if (isDeep(sort)) return deepToMap(sort);111 if (isPair(sort)) return pairToMap(sort);112 return stringsToMap(sort);...
sort_test.py
Source:sort_test.py
...9from chapter8.radix_sort import radix_sort10from chapter8.bucket_sort import bucket_sort11RANDOM_SORT_TEST_INPUT = 'test/random_sort_test_cases.json'12class SortTest(unittest.TestCase):13 def _test_sort(self, sort: Callable[[List[int], bool], List[int]]):14 test_cases = [15 ([4, 7, 1, 5, 8, 2, 6, 9, 10, 3], False, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),16 ([7, 6, 5, 4, 3, 2, 1], False, [1, 2, 3, 4, 5, 6, 7]),17 ([1, 2, 3, 4, 5, 6, 7], True, [7, 6, 5, 4, 3, 2, 1])18 ]19 for nums, reverse, expected in test_cases:20 result = sort(nums, reverse)21 self.assertEqual(expected, result)22 with open(RANDOM_SORT_TEST_INPUT) as f:23 random_test_cases = json.load(f)24 for nums in random_test_cases:25 result = sort(nums, False)26 benchmark = sorted(nums)27 self.assertEqual(result, benchmark)28 def test_insertion_sort(self):29 self._test_sort(insertion_sort)30 def test_merge_sort(self):31 self._test_sort(merge_sort)32 def test_heap_sort(self):33 def sort(nums: List[int], reverse: bool) -> List[int]:34 heap_sort(nums, reverse)35 return nums36 self._test_sort(sort)37 def test_quick_sort(self):38 def sort(nums: List[int], reverse: bool) -> List[int]:39 quick_sort(nums, 0, len(nums) - 1, reverse)40 return nums41 self._test_sort(sort)42 def test_counting_sort(self):43 def sort(nums: List[int], reverse: bool) -> List[int]:44 return counting_sort(nums, (-10000, 10000), reverse)45 self._test_sort(sort)46 def test_radix_sort(self):47 self._test_sort(radix_sort)48 def test_bucket_sort(self):49 def sort(nums: List[int], reverse: bool) -> List[int]:50 return bucket_sort(nums, (-10000, 10000), reverse)51 self._test_sort(sort)52 53if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!